mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Refactor media attachments to use MediaFile entity
This commit introduces the MediaFile entity and updates the media attachments model, repositories, and related logic to reference MediaFile instead of storing file metadata directly in MediaAttachments. Controller, service, and SignalR request/response contracts are updated to support the new structure. Database configurations and validators are also adjusted accordingly. This refactor improves media management and normalization in the data model.
This commit is contained in:
@@ -15,10 +15,8 @@ public class MediaAttachmentsValidator : IObjectValidator<MediaAttachments>
|
||||
throw new ArgumentException("Id cannot be empty", nameof(attachments));
|
||||
if(attachments.MessageId == Guid.Empty)
|
||||
throw new ArgumentException("MessageId cannot be empty", nameof(attachments));
|
||||
if(string.IsNullOrWhiteSpace(attachments.FilePath))
|
||||
if(string.IsNullOrWhiteSpace(attachments.MediaFile.Url))
|
||||
throw new ArgumentException("File path cannot be empty", nameof(attachments));
|
||||
if(string.IsNullOrWhiteSpace(attachments.EncryptedKey))
|
||||
throw new ArgumentException("Encrypted key cannot be empty", nameof(attachments));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -4,22 +4,16 @@ public class MediaAttachments
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid MessageId { get; set; }
|
||||
public MediaType Type { get; set; }
|
||||
public string FilePath { get; set; } = string.Empty; // local path in filesystem
|
||||
public string MimeType { get; set; } = string.Empty;
|
||||
public string? EncryptedKey { get; set; }
|
||||
public Message Message { get; set; } = null!;
|
||||
|
||||
public Guid MediaFileId { get; set; }
|
||||
public Message Message { get; set; }
|
||||
public MediaFile MediaFile { get; set; }
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is not MediaAttachments other) return false;
|
||||
|
||||
return Id == other.Id &&
|
||||
MessageId == other.MessageId &&
|
||||
EncryptedKey == other.EncryptedKey &&
|
||||
Type == other.Type &&
|
||||
FilePath == other.FilePath &&
|
||||
MimeType == other.MimeType;
|
||||
MediaFileId == other.MediaFileId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Govor.Core.Models;
|
||||
|
||||
public class MediaFile
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Url { get; set; }
|
||||
public MediaType MediaType { get; set; }
|
||||
public string MineType { get; set; }
|
||||
public DateTime DateCreated { get; set; }
|
||||
}
|
||||
@@ -15,7 +15,6 @@ public class Message
|
||||
public List<MessageView> MessageViews { get; set; } = new List<MessageView>();
|
||||
|
||||
public Guid? ReplyToMessageId { get; set; }
|
||||
public Message? ReplyToMessage { get; set; } // navigation
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user