diff --git a/Govor.Core/Models/MediaAttachments.cs b/Govor.Core/Models/MediaAttachments.cs index b26f857..df65431 100644 --- a/Govor.Core/Models/MediaAttachments.cs +++ b/Govor.Core/Models/MediaAttachments.cs @@ -6,10 +6,10 @@ public class MediaAttachments public Guid MessageId { get; set; } public MediaType Type { get; set; } - public string FilePath { get; set; } = string.Empty; // путь к файлу (локальный или URL) + public string FilePath { get; set; } = string.Empty; // local path in filesystem public string MimeType { get; set; } = string.Empty; - public string? EncryptedKey { get; set; } // если используется отдельное шифрование + public string? EncryptedKey { get; set; } public Message Message { get; set; } = null!; } diff --git a/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsExist.cs b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsExist.cs new file mode 100644 index 0000000..506a7db --- /dev/null +++ b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsExist.cs @@ -0,0 +1,9 @@ +using Govor.Core.Models; + +namespace Govor.Core.Repositories.MediasAttachments; + +public interface IMediaAttachmentsExist +{ + bool Exists(Guid id); + bool Exists(MediaAttachments attachments); +} \ No newline at end of file diff --git a/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsReader.cs b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsReader.cs new file mode 100644 index 0000000..b9cd531 --- /dev/null +++ b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsReader.cs @@ -0,0 +1,9 @@ +using Govor.Core.Models; + +namespace Govor.Core.Repositories.MediasAttachments; + +public interface IMediaAttachmentsReader +{ + Task> GetAllAsync(); + Task> GetAllByMessageId(Guid messageId); +} \ No newline at end of file diff --git a/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsRepository.cs b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsRepository.cs new file mode 100644 index 0000000..457e84d --- /dev/null +++ b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsRepository.cs @@ -0,0 +1,6 @@ +namespace Govor.Core.Repositories.MediasAttachments; + +public interface IMediaAttachmentsRepository : IMediaAttachmentsReader, IMediaAttachmentsWriter, IMediaAttachmentsExist +{ + +} \ No newline at end of file diff --git a/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsWriter.cs b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsWriter.cs new file mode 100644 index 0000000..27cc2b4 --- /dev/null +++ b/Govor.Core/Repositories/MediasAttachments/IMediaAttachmentsWriter.cs @@ -0,0 +1,10 @@ +using Govor.Core.Models; + +namespace Govor.Core.Repositories.MediasAttachments; + +public interface IMediaAttachmentsWriter +{ + Task AddAsync(MediaAttachments mediaAttachments); + Task UpdateAsync(MediaAttachments mediaAttachments); + Task RemoveAsync(Guid Id); +} \ No newline at end of file diff --git a/Govor.Data/Repositories/MediaAttachmentsRepository.cs b/Govor.Data/Repositories/MediaAttachmentsRepository.cs new file mode 100644 index 0000000..8707fe9 --- /dev/null +++ b/Govor.Data/Repositories/MediaAttachmentsRepository.cs @@ -0,0 +1,58 @@ +using Govor.Core.Infrastructure.Extensions; +using Govor.Core.Infrastructure.Validators; +using Govor.Core.Models; +using Govor.Core.Repositories.MediasAttachments; +using Govor.Data.Repositories.Exceptions; +using Microsoft.EntityFrameworkCore; + +namespace Govor.Data.Repositories; + +public class MediaAttachmentsRepository : IMediaAttachmentsRepository +{ + public IObjectValidator _validator; + public GovorDbContext _context; + + public MediaAttachmentsRepository(GovorDbContext context, IObjectValidator validator) + { + _context = context; + _validator = validator; + } + + public async Task> GetAllAsync() + { + return await _context.MediaAttachments + .AsNoTracking() + .Include(ma => ma.Message) + .ToListOrThrowIfEmpty(new NotFoundException("No media attachments found.")); + } + + public Task> GetAllByMessageId(Guid messageId) + { + throw new NotImplementedException(); + } + + public Task AddAsync(MediaAttachments mediaAttachments) + { + throw new NotImplementedException(); + } + + public Task UpdateAsync(MediaAttachments mediaAttachments) + { + throw new NotImplementedException(); + } + + public Task RemoveAsync(Guid Id) + { + throw new NotImplementedException(); + } + + public bool Exists(Guid id) + { + throw new NotImplementedException(); + } + + public bool Exists(MediaAttachments attachments) + { + throw new NotImplementedException(); + } +} \ No newline at end of file