From 5e892b7127e816c11c0c2bfbf8b69f8bdce36ecf Mon Sep 17 00:00:00 2001 From: LuisMend12 Date: Sat, 25 Jan 2025 13:59:02 -0500 Subject: [PATCH] UserPrivateInfo.cs I added a new line of code in User.cs --- Valour/Database/User.cs | 9 ++++- Valour/Database/UserPrivateInfo.cs | 63 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Valour/Database/User.cs b/Valour/Database/User.cs index 11587d8f..6878833e 100644 --- a/Valour/Database/User.cs +++ b/Valour/Database/User.cs @@ -50,7 +50,14 @@ public class User : ISharedUser /// Channel states for this user. /// public virtual ICollection ChannelStates { get; set; } - + + /// + /// Privateinfo for this user. + /// + public virtual ICollection UserPrivateInfo { get; set; } + + + /////////////////////// // Entity Properties // /////////////////////// diff --git a/Valour/Database/UserPrivateInfo.cs b/Valour/Database/UserPrivateInfo.cs index b17c7108..a43b4b19 100644 --- a/Valour/Database/UserPrivateInfo.cs +++ b/Valour/Database/UserPrivateInfo.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; +using Microsoft.EntityFrameworkCore; using Valour.Shared.Models; namespace Valour.Database; @@ -64,5 +65,67 @@ public class UserPrivateInfo : ISharedUserPrivateInfo /// [Column("join_source")] public string JoinSource { get; set; } + + + public static void SetUpDDModel(ModelBuilder builder) + { + builder.Entity(e => + { + // ToTable + e.ToTable("user_private_info"); + + // key + e.HasKey(x => x.Email); + + // Property + e.Property(x => x.Email) + .HasColumnName("email"); + + e.Property(x => x.Verified) + .HasColumnName("verified"); + + e.Property(x => x.UserId) + .HasColumnName("user_id"); + + e.Property(x => x.BirthDate) + .HasColumnName("birth_date") + .HasConversion( + x => x, + x => x == null ? null : new DateTime(x.Value.Ticks, DateTimeKind.Utc) + ); + + e.Property(x => x.Locality) + .HasColumnName("locality") + .HasConversion( + x => x.ToString(), + x => (Locality)Enum.Parse(typeof(Locality), x) + ); + + e.Property(x => x.JoinInviteCode) + .HasColumnName("join_invite_code"); + + e.Property(x => x.JoinSource) + .HasColumnName("join_source"); + + // Relationships + + e.HasOne(x => x.User) + .WithMany(x => x.UserPrivateInfo) + .HasForeignKey(x => x.UserId); + + // Indices + + e.HasIndex(x => x.UserId) + .IsUnique(); + + e.HasIndex(x => x.BirthDate); + + e.HasIndex(x => x.Locality); + + e.HasIndex(x => x.JoinInviteCode); + + e.HasIndex(x => x.Email); + }); + } }