mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Update models Messages
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using Govor.Core.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Data.Configurations;
|
||||
|
||||
public class MediaAttachmentsConfiguration : IEntityTypeConfiguration<MediaAttachments>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<MediaAttachments> builder)
|
||||
{
|
||||
builder.HasKey(ma => ma.Id);
|
||||
|
||||
builder.Property(ma => ma.FilePath)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(ma => ma.MimeType)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(ma => ma.EncryptedKey)
|
||||
.HasMaxLength(512); // зависит от шифра
|
||||
|
||||
builder.Property(ma => ma.Type)
|
||||
.HasConversion<string>() // enum as string (e.g., "Image")
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Govor.Core.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Data.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.Core.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Data.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,36 @@
|
||||
using Govor.Core.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Govor.Data.Configurations;
|
||||
|
||||
public class MessagesConfiguration : IEntityTypeConfiguration<Message>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Message> builder)
|
||||
{
|
||||
builder.HasKey(m => m.Id);
|
||||
|
||||
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.HasOne(m => m.ReplyToMessage)
|
||||
.WithMany()
|
||||
.HasForeignKey(m => m.ReplyToMessageId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.Property(m => m.EncryptedContent)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user