Skip to content

Commit

Permalink
UserPrivateInfo.cs
Browse files Browse the repository at this point in the history
I added a new line of code in User.cs
  • Loading branch information
LuisMend12 committed Jan 25, 2025
1 parent b521697 commit 5e892b7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Valour/Database/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public class User : ISharedUser
/// Channel states for this user.
/// </summary>
public virtual ICollection<UserChannelState> ChannelStates { get; set; }


/// <summary>
/// Privateinfo for this user.
/// </summary>
public virtual ICollection<UserPrivateInfo> UserPrivateInfo { get; set; }



///////////////////////
// Entity Properties //
///////////////////////
Expand Down
63 changes: 63 additions & 0 deletions Valour/Database/UserPrivateInfo.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -64,5 +65,67 @@ public class UserPrivateInfo : ISharedUserPrivateInfo
/// </summary>
[Column("join_source")]
public string JoinSource { get; set; }


public static void SetUpDDModel(ModelBuilder builder)
{
builder.Entity<UserPrivateInfo>(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);
});
}
}

0 comments on commit 5e892b7

Please sign in to comment.