mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
Refactor: migrate Core -> Domain and reorganize projects
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using Govor.Domain.Models.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class AdminConfiguration : IEntityTypeConfiguration<Admin>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Admin> builder)
|
||||
{
|
||||
builder.HasKey(a => a.UserId);
|
||||
|
||||
builder.HasOne(a => a.User)
|
||||
.WithOne()
|
||||
.HasForeignKey<Admin>(a => a.UserId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class ChatGroupConfigurator : IEntityTypeConfiguration<ChatGroup>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ChatGroup> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.Name).IsRequired().HasMaxLength(100);
|
||||
builder.Property(e => e.Description).HasMaxLength(500);
|
||||
|
||||
builder.HasMany(e => e.Members)
|
||||
.WithOne()
|
||||
.HasForeignKey(e => e.GroupId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(e => e.Admins)
|
||||
.WithOne()
|
||||
.HasForeignKey(e => e.GroupId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(e => e.InviteCodes)
|
||||
.WithOne()
|
||||
.HasForeignKey(e => e.GroupId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class FriendshipConfiguration : IEntityTypeConfiguration<Friendship>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Friendship> builder)
|
||||
{
|
||||
builder.HasKey(f => f.Id);
|
||||
|
||||
builder.HasOne(f => f.Requester)
|
||||
.WithMany(u => u.SentFriendRequests)
|
||||
.HasForeignKey(f => f.RequesterId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Addressee)
|
||||
.WithMany(u => u.ReceivedFriendRequests)
|
||||
.HasForeignKey(f => f.AddresseeId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.Property(f => f.Status)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class GroupAdminsConfiguration : IEntityTypeConfiguration<GroupAdmins>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<GroupAdmins> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.UserId).IsRequired();
|
||||
builder.Property(e => e.GroupId).IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class GroupInvitationConfiguration : IEntityTypeConfiguration<GroupInvitation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<GroupInvitation> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.InvitationCode).IsRequired().HasMaxLength(200);
|
||||
builder.Property(e => e.Description).HasMaxLength(500);
|
||||
builder.Property(e => e.EndDate).IsRequired();
|
||||
builder.Property(e => e.CreatedAt).IsRequired();
|
||||
|
||||
builder.HasOne(e => e.UserMaker)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.UserMakerId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
|
||||
builder.Ignore(e => e.GroupMemberships);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class GroupMembershipConfiguration : IEntityTypeConfiguration<GroupMembership>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<GroupMembership> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.UserId).IsRequired();
|
||||
builder.Property(e => e.GroupId).IsRequired();
|
||||
builder.Property(e => e.InvitationId).IsRequired(false);
|
||||
|
||||
builder.HasOne(e => e.ChatGroup)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.GroupId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// Optional: настройка связи с GroupInvitation
|
||||
builder.HasOne<GroupInvitation>()
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.InvitationId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class InvitationConfiguration : IEntityTypeConfiguration<Invitation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Invitation> builder)
|
||||
{
|
||||
builder.HasKey(i => i.Id);
|
||||
|
||||
builder.HasMany(i => i.Users)
|
||||
.WithOne(u => u.Invite)
|
||||
.HasForeignKey(u => u.InviteId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class MediaAttachmentsConfiguration : IEntityTypeConfiguration<MediaAttachments>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<MediaAttachments> builder)
|
||||
{
|
||||
builder.HasKey(ma => ma.Id);
|
||||
|
||||
builder.HasOne(ma => ma.Message)
|
||||
.WithMany(m => m.MediaAttachments)
|
||||
.HasForeignKey(ma => ma.MessageId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(ma => ma.MediaFile)
|
||||
.WithMany()
|
||||
.HasForeignKey(ma => ma.MediaFileId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class MediaFileConfiguration : IEntityTypeConfiguration<MediaFile>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<MediaFile> builder)
|
||||
{
|
||||
builder.HasKey(ma => ma.Id);
|
||||
|
||||
builder.Property(mf => mf.Url)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(mf => mf.MediaType)
|
||||
.HasConversion<string>() // enum as string (e.g., "Image")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(ma => ma.MineType)
|
||||
.HasMaxLength(128)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(mf => mf.DateCreated)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class MessageReactionConfiguration : IEntityTypeConfiguration<MessageReaction>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<MessageReaction> builder)
|
||||
{
|
||||
builder.HasKey(r => r.Id);
|
||||
|
||||
builder.HasIndex(r => new { r.MessageId, r.UserId }).IsUnique(); // Одна реакция от одного юзера
|
||||
|
||||
builder.Property(r => r.ReactionCode)
|
||||
.IsRequired()
|
||||
.HasMaxLength(64); // можно увеличить для кастомных эмодзи
|
||||
|
||||
builder.HasOne(r => r.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(r => r.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class MessageViewConfiguration : IEntityTypeConfiguration<MessageView>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<MessageView> builder)
|
||||
{
|
||||
builder.HasKey(mv => mv.Id);
|
||||
|
||||
builder.HasIndex(mv => new { mv.MessageId, mv.UserId }).IsUnique();
|
||||
|
||||
builder.Property(mv => mv.ViewedAt)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class MessagesConfiguration : IEntityTypeConfiguration<Message>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Message> builder)
|
||||
{
|
||||
builder.HasKey(m => m.Id);
|
||||
|
||||
// Просто индекс, без unique
|
||||
builder.HasIndex(m => m.RecipientId);
|
||||
|
||||
builder.HasMany(m => m.Reactions)
|
||||
.WithOne(r => r.Message)
|
||||
.HasForeignKey(r => r.MessageId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(m => m.MediaAttachments)
|
||||
.WithOne(ma => ma.Message)
|
||||
.HasForeignKey(ma => ma.MessageId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(m => m.MessageViews)
|
||||
.WithOne()
|
||||
.HasForeignKey(mv => mv.MessageId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Property(m => m.EncryptedContent)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Govor.Domain.Models.Users.Crypto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class OneTimePreKeyConfiguration : IEntityTypeConfiguration<OneTimePreKey>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OneTimePreKey> builder)
|
||||
{
|
||||
// Первичный ключ
|
||||
builder.HasKey(otpk => otpk.Id);
|
||||
|
||||
builder.HasOne(otpk => otpk.UserCryptoSession)
|
||||
.WithMany(ucs => ucs.OneTimePreKeys)
|
||||
.HasForeignKey(otpk => otpk.UserCryptoSessionId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Property(otpk => otpk.PublicKey)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(otpk => otpk.IsUsed)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
builder.Property(otpk => otpk.UploadedAt)
|
||||
.IsRequired();
|
||||
|
||||
builder.HasIndex(otpk => new { otpk.UserCryptoSessionId, otpk.IsUsed });
|
||||
builder.HasIndex(otpk => otpk.UploadedAt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Govor.Domain.Models.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class PrivacyRuleEntityConfiguration : IEntityTypeConfiguration<PrivacyRuleEntity>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<PrivacyRuleEntity> builder)
|
||||
{
|
||||
builder.HasKey(r => r.Id);
|
||||
|
||||
builder.Property(r => r.OwnerId).IsRequired();
|
||||
builder.Property(r => r.Area).IsRequired().HasConversion<string>();
|
||||
builder.Property(r => r.AccessType).IsRequired().HasConversion<string>();
|
||||
|
||||
builder.Property(r => r.Whitelist).HasColumnType("jsonb");
|
||||
builder.Property(r => r.Blacklist).HasColumnType("jsonb");
|
||||
|
||||
builder.HasIndex(r => r.OwnerId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Govor.Domain.Models.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class PrivacyUserSettingsConfiguration : IEntityTypeConfiguration<PrivacyUserSettings>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<PrivacyUserSettings> builder)
|
||||
{
|
||||
// Primary Key
|
||||
builder.HasKey(p => p.UserId);
|
||||
|
||||
builder.Property(p => p.DeletingVia)
|
||||
.IsRequired()
|
||||
.HasConversion<string>()
|
||||
.HasDefaultValue(DeletingMessagesVia.None); // Adjust default as needed
|
||||
|
||||
builder.Property(p => p.DeletingIn)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(0);
|
||||
|
||||
// Relationship Configuration
|
||||
builder.HasMany(p => p.Rules)
|
||||
.WithOne(r => r.OwnerSettings)
|
||||
.HasForeignKey(r => r.OwnerId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class PrivateChatsConfiguration : IEntityTypeConfiguration<PrivateChat>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<PrivateChat> builder)
|
||||
{
|
||||
builder.HasKey(us => us.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Govor.Domain.Models.Users.Crypto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class SignedPreKeyConfiguration : IEntityTypeConfiguration<SignedPreKey>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<SignedPreKey> builder)
|
||||
{
|
||||
builder.HasKey(spk => spk.Id);
|
||||
|
||||
builder.HasOne(spk => spk.UserCryptoSession)
|
||||
.WithOne(ucs => ucs.SignedPreKey)
|
||||
.HasForeignKey<SignedPreKey>(spk => spk.UserCryptoSessionId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Property(spk => spk.PublicSignedPreKey)
|
||||
.IsRequired();
|
||||
builder.Property(spk => spk.SignedPreKeySignature)
|
||||
.IsRequired();
|
||||
|
||||
builder.HasIndex(spk => spk.UserCryptoSessionId)
|
||||
.IsUnique();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Govor.Domain.Models.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<User> builder)
|
||||
{
|
||||
builder.HasKey(x => x.Id);
|
||||
|
||||
builder.HasIndex(u => u.Username).IsUnique();
|
||||
builder.HasIndex(u => u.CreatedOn);
|
||||
builder.HasIndex(u => u.WasOnline);
|
||||
|
||||
builder.HasOne(u => u.Invite)
|
||||
.WithMany(i => i.Users)
|
||||
.HasForeignKey(u => u.InviteId);
|
||||
|
||||
builder.Property(u => u.Username)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.HasIndex(u => u.Username).IsUnique();
|
||||
|
||||
builder.Property(u => u.Description)
|
||||
.HasMaxLength(500)
|
||||
.IsRequired(false);
|
||||
|
||||
builder.Property(u => u.PasswordHash)
|
||||
.IsRequired()
|
||||
.HasMaxLength(128);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Govor.Domain.Models.Users.Crypto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class UserCryptoSessionConfiguration : IEntityTypeConfiguration<UserCryptoSession>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserCryptoSession> builder)
|
||||
{
|
||||
builder.HasKey(ucs => ucs.Id);
|
||||
|
||||
builder.HasOne(ucs => ucs.UserSession)
|
||||
.WithOne(us => us.CryptoSession)
|
||||
.HasForeignKey<UserCryptoSession>(ucs => ucs.UserSessionId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(ucs => ucs.SignedPreKey)
|
||||
.WithOne(spk => spk.UserCryptoSession)
|
||||
.HasForeignKey<SignedPreKey>(spk => spk.UserCryptoSessionId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(ucs => ucs.OneTimePreKeys)
|
||||
.WithOne(otpk => otpk.UserCryptoSession)
|
||||
.HasForeignKey(otpk => otpk.UserCryptoSessionId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(ucs => ucs.UserSessionId)
|
||||
.IsUnique();
|
||||
|
||||
builder.Property(ucs => ucs.PublicIdentityKey)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Govor.Domain.Models.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class UserPushTokenConfiguration : IEntityTypeConfiguration<UserPushToken>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserPushToken> builder)
|
||||
{
|
||||
builder.HasKey(t => t.Id);
|
||||
|
||||
builder.HasIndex(x => x.Token)
|
||||
.IsUnique();
|
||||
|
||||
builder.HasIndex(x => x.UserSessionId)
|
||||
.IsUnique();
|
||||
|
||||
builder.HasIndex(x => new { x.UserId, x.IsActive });
|
||||
|
||||
builder.Property(x => x.Token)
|
||||
.IsRequired()
|
||||
.HasMaxLength(512);
|
||||
|
||||
builder.Property(x => x.Platform)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(x => x.Provider)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Govor.Domain.Models.Users;
|
||||
using Govor.Domain.Models.Users.Crypto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Domain.Configurations;
|
||||
|
||||
public class UserSessionConfiguration : IEntityTypeConfiguration<UserSession>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserSession> builder)
|
||||
{
|
||||
builder.HasKey(us => us.Id);
|
||||
|
||||
builder.HasIndex(us => us.UserId);
|
||||
|
||||
builder.HasIndex(s => s.RefreshTokenHash)
|
||||
.IsUnique();
|
||||
|
||||
builder.Property(us => us.RefreshTokenHash)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(us => us.DeviceInfo)
|
||||
.HasMaxLength(256);
|
||||
|
||||
builder.HasOne(us => us.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(us => us.UserId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(e => e.CryptoSession)
|
||||
.WithOne(e => e.UserSession)
|
||||
.HasForeignKey<UserCryptoSession>(e => e.UserSessionId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user