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:
@@ -75,12 +75,24 @@ public class MessageValidatorTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Given_EmptyEncryptedMessage_When_Validate_Should_Throw_InvalidObjectException()
|
public void Given_EmptyEncryptedMessageAndNotEmptyMedia_When_Validate_Should_Throw_InvalidObjectException()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Message message = _fixture.Create<Message>();
|
Message message = _fixture.Create<Message>();
|
||||||
message.EncryptedContent = string.Empty;
|
message.EncryptedContent = string.Empty;
|
||||||
|
|
||||||
|
Assert.DoesNotThrowAsync(async () => _messageValidator.Validate(message));
|
||||||
|
Assert.That(_messageValidator.TryValidate(message), Is.True);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Given_EmptyEncryptedMessageAndEmptyMedia_When_Validate_Should_Throw_InvalidObjectException()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
Message message = _fixture.Create<Message>();
|
||||||
|
message.EncryptedContent = string.Empty;
|
||||||
|
message.MediaAttachments = default;
|
||||||
|
|
||||||
Assert.ThrowsAsync<InvalidObjectException<Message>>(async () => _messageValidator.Validate(message));
|
Assert.ThrowsAsync<InvalidObjectException<Message>>(async () => _messageValidator.Validate(message));
|
||||||
Assert.That(_messageValidator.TryValidate(message), Is.False);
|
Assert.That(_messageValidator.TryValidate(message), Is.False);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class LocalStorageService : IStorageService
|
|||||||
|
|
||||||
public async Task<Stream> LoadAsync(string url)
|
public async Task<Stream> LoadAsync(string url)
|
||||||
{
|
{
|
||||||
var filePath = Path.Combine(_storagePath, url); // url уже включает yyyy/MM
|
var filePath = Path.Combine(_storagePath, url);
|
||||||
|
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
throw new FileNotFoundException("File not found.", filePath);
|
throw new FileNotFoundException("File not found.", filePath);
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ public class MessageValidator : IObjectValidator<Message>
|
|||||||
throw new ArgumentException("Sender ID cannot be empty", nameof(message.SenderId));
|
throw new ArgumentException("Sender ID cannot be empty", nameof(message.SenderId));
|
||||||
if (message.RecipientId == Guid.Empty)
|
if (message.RecipientId == Guid.Empty)
|
||||||
throw new ArgumentException("Recipient ID cannot be empty", nameof(message.RecipientId));
|
throw new ArgumentException("Recipient ID cannot be empty", nameof(message.RecipientId));
|
||||||
if(string.IsNullOrWhiteSpace(message.EncryptedContent))
|
if(string.IsNullOrWhiteSpace(message.EncryptedContent) && (message.MediaAttachments is null || message.MediaAttachments.Count == 0))
|
||||||
throw new ArgumentException("Encrypted content cannot be empty", nameof(message.EncryptedContent));
|
throw new ArgumentException("Encrypted content cannot be empty when media attachments are empty", nameof(message.EncryptedContent));
|
||||||
if(message.IsEdited && message.EditedAt == DateTime.MinValue)
|
if(message.IsEdited && message.EditedAt == DateTime.MinValue)
|
||||||
throw new ArgumentException("Edited at time cannot be empty", nameof(message.EditedAt));
|
throw new ArgumentException("Edited at time cannot be empty", nameof(message.EditedAt));
|
||||||
if (message.SentAt == DateTime.MinValue)
|
if (message.SentAt == DateTime.MinValue)
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ public class Message
|
|||||||
public DateTime? EditedAt { get; set; }
|
public DateTime? EditedAt { get; set; }
|
||||||
public List<MessageReaction> Reactions { get; set; } = new List<MessageReaction>();
|
public List<MessageReaction> Reactions { get; set; } = new List<MessageReaction>();
|
||||||
public List<MediaAttachments> MediaAttachments { get; set; } = new List<MediaAttachments>();
|
public List<MediaAttachments> MediaAttachments { get; set; } = new List<MediaAttachments>();
|
||||||
|
public List<MessageView> MessageViews { get; set; } = new List<MessageView>();
|
||||||
|
|
||||||
|
public Guid? ReplyToMessageId { get; set; }
|
||||||
|
public Message? ReplyToMessage { get; set; } // navigation
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RecipientType
|
public enum RecipientType
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Govor.Core.Models;
|
||||||
|
|
||||||
|
public class MessageView
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid MessageId { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public DateTime ViewedAt { get; set; }
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Govor.Core.Models;
|
using Govor.Core.Models;
|
||||||
|
using Govor.Data.Configurations;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Govor.Data;
|
namespace Govor.Data;
|
||||||
@@ -7,8 +8,23 @@ namespace Govor.Data;
|
|||||||
public class GovorDbContext(DbContextOptions<GovorDbContext> options) : DbContext(options)
|
public class GovorDbContext(DbContextOptions<GovorDbContext> options) : DbContext(options)
|
||||||
{
|
{
|
||||||
public virtual DbSet<User> Users { get; set; }
|
public virtual DbSet<User> Users { get; set; }
|
||||||
public virtual DbSet<ChatGroup> ChatGroups { get; set; }
|
|
||||||
public virtual DbSet<Message> Messages { get; set; }
|
public virtual DbSet<Message> Messages { get; set; }
|
||||||
|
public virtual DbSet<MessageView> MessageViews { get; set; }
|
||||||
|
public virtual DbSet<MessageReaction> MessageReactions { get; set; }
|
||||||
|
public virtual DbSet<MediaAttachments> MediaAttachments { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<ChatGroup> ChatGroups { get; set; }
|
||||||
public virtual DbSet<GroupMembership> GroupMemberships { get; set; }
|
public virtual DbSet<GroupMembership> GroupMemberships { get; set; }
|
||||||
public virtual DbSet<GroupAdmins> GroupAdmins { get; set; }
|
public virtual DbSet<GroupAdmins> GroupAdmins { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new MessagesConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new MessageReactionConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new MediaAttachmentsConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new MessageViewConfiguration());
|
||||||
|
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,310 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Govor.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Govor.Data.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(GovorDbContext))]
|
||||||
|
[Migration("20250622044435_MessagesInit")]
|
||||||
|
partial class MessagesInit
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.6")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.ChatGroup", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<List<Guid>>("Admins")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("uuid[]");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<List<string>>("InviteCode")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<bool>("IsChannel")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("IsPrivate")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ChatGroups");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.GroupAdmins", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("GroupId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("GroupAdmins");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.GroupMembership", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("GroupId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<bool>("IsBanned")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("GroupMemberships");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("EncryptedKey")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("FilePath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("MimeType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId");
|
||||||
|
|
||||||
|
b.ToTable("MediaAttachments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("EditedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("EncryptedContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEdited")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<Guid>("RecipientId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<int>("RecipientType")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ReplyToMessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("SenderId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("SentAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ReplyToMessageId");
|
||||||
|
|
||||||
|
b.ToTable("Messages");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageReaction", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ReactedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ReactionCode")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MessageReactions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageView", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ViewedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MessageViews");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateOnly>("CreatedOn")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("IconId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("WasOnline")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", "Message")
|
||||||
|
.WithMany("MediaAttachments")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Message");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", "ReplyToMessage")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ReplyToMessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
|
b.Navigation("ReplyToMessage");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageReaction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", "Message")
|
||||||
|
.WithMany("Reactions")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Govor.Core.Models.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Message");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageView", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", null)
|
||||||
|
.WithMany("MessageViews")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("MediaAttachments");
|
||||||
|
|
||||||
|
b.Navigation("MessageViews");
|
||||||
|
|
||||||
|
b.Navigation("Reactions");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Govor.Data.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class MessagesInit : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Messages",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
SenderId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
RecipientId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
RecipientType = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
EncryptedContent = table.Column<string>(type: "text", nullable: false),
|
||||||
|
SentAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
IsEdited = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
EditedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||||
|
ReplyToMessageId = table.Column<Guid>(type: "uuid", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Messages", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Messages_Messages_ReplyToMessageId",
|
||||||
|
column: x => x.ReplyToMessageId,
|
||||||
|
principalTable: "Messages",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MediaAttachments",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
MessageId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
Type = table.Column<string>(type: "text", nullable: false),
|
||||||
|
FilePath = table.Column<string>(type: "text", nullable: false),
|
||||||
|
MimeType = table.Column<string>(type: "text", nullable: false),
|
||||||
|
EncryptedKey = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MediaAttachments", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MediaAttachments_Messages_MessageId",
|
||||||
|
column: x => x.MessageId,
|
||||||
|
principalTable: "Messages",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MessageReactions",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
MessageId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
ReactionCode = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
ReactedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MessageReactions", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MessageReactions_Messages_MessageId",
|
||||||
|
column: x => x.MessageId,
|
||||||
|
principalTable: "Messages",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MessageReactions_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MessageViews",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
MessageId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
ViewedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MessageViews", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MessageViews_Messages_MessageId",
|
||||||
|
column: x => x.MessageId,
|
||||||
|
principalTable: "Messages",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MediaAttachments_MessageId",
|
||||||
|
table: "MediaAttachments",
|
||||||
|
column: "MessageId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MessageReactions_MessageId_UserId",
|
||||||
|
table: "MessageReactions",
|
||||||
|
columns: new[] { "MessageId", "UserId" },
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MessageReactions_UserId",
|
||||||
|
table: "MessageReactions",
|
||||||
|
column: "UserId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Messages_ReplyToMessageId",
|
||||||
|
table: "Messages",
|
||||||
|
column: "ReplyToMessageId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MessageViews_MessageId_UserId",
|
||||||
|
table: "MessageViews",
|
||||||
|
columns: new[] { "MessageId", "UserId" },
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MediaAttachments");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MessageReactions");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MessageViews");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Messages");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,6 +89,129 @@ namespace Govor.Data.Migrations
|
|||||||
b.ToTable("GroupMemberships");
|
b.ToTable("GroupMemberships");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("EncryptedKey")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("FilePath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("MimeType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId");
|
||||||
|
|
||||||
|
b.ToTable("MediaAttachments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("EditedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("EncryptedContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEdited")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<Guid>("RecipientId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<int>("RecipientType")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ReplyToMessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("SenderId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("SentAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ReplyToMessageId");
|
||||||
|
|
||||||
|
b.ToTable("Messages");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageReaction", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ReactedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ReactionCode")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MessageReactions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageView", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ViewedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MessageViews");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Govor.Core.Models.User", b =>
|
modelBuilder.Entity("Govor.Core.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -120,6 +243,64 @@ namespace Govor.Data.Migrations
|
|||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", "Message")
|
||||||
|
.WithMany("MediaAttachments")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Message");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", "ReplyToMessage")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ReplyToMessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
|
b.Navigation("ReplyToMessage");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageReaction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", "Message")
|
||||||
|
.WithMany("Reactions")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Govor.Core.Models.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Message");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.MessageView", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Govor.Core.Models.Message", null)
|
||||||
|
.WithMany("MessageViews")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Govor.Core.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("MediaAttachments");
|
||||||
|
|
||||||
|
b.Navigation("MessageViews");
|
||||||
|
|
||||||
|
b.Navigation("Reactions");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user