feat(application): add EmailSyncResult DTO, Folder/AccountId to ReceivedEmailDto, rename CreateRangeAsync in IRepository, update IImapEmailService signature, add AutoMapper profiles for ReceivedEmail and EmailAttachment
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
#if NET
|
||||||
|
namespace DigitalData.MessagingService.Application.Common.Dto;
|
||||||
|
|
||||||
|
public record EmailSyncResult(int ProcessedCount = 0, int FailedCount = 0);
|
||||||
|
#endif
|
||||||
@@ -14,6 +14,15 @@ public sealed record ReceivedEmailDto
|
|||||||
public long Uid { get; set; }
|
public long Uid { get; set; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ID of the email account this message belongs to.
|
||||||
|
/// </summary>
|
||||||
|
#if NET
|
||||||
|
public int AccountId { get; init; }
|
||||||
|
#else
|
||||||
|
public int AccountId { get; set; }
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sender address (From header).
|
/// Sender address (From header).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -94,4 +103,10 @@ public sealed record ReceivedEmailDto
|
|||||||
#else
|
#else
|
||||||
public bool IsSeen { get; set; }
|
public bool IsSeen { get; set; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
public required string Folder { get; init; }
|
||||||
|
#else
|
||||||
|
public string Folder { get; set; } = null!;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#if NET
|
#if NET
|
||||||
using DigitalData.MessagingService.Application.Common.Dto;
|
using DigitalData.MessagingService.Application.Common.Dto;
|
||||||
using DigitalData.MessagingService.Application.Common.Dto.MailSearch;
|
|
||||||
using DigitalData.MessagingService.Domain.Entities;
|
using DigitalData.MessagingService.Domain.Entities;
|
||||||
|
|
||||||
namespace DigitalData.MessagingService.Application.Common.Interfaces;
|
namespace DigitalData.MessagingService.Application.Common.Interfaces;
|
||||||
@@ -11,19 +10,16 @@ namespace DigitalData.MessagingService.Application.Common.Interfaces;
|
|||||||
public interface IImapEmailService
|
public interface IImapEmailService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches emails from the specified mailbox folder.
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="account">Account whose IMAP settings will be used.</param>
|
/// <param name="account"></param>
|
||||||
/// <param name="date"></param>
|
/// <param name="folder"></param>
|
||||||
/// When <see langword="true"/> (default), fetched messages are marked as <c>\Seen</c> on the server.
|
/// <param name="cancel"></param>
|
||||||
/// Set to <see langword="false"/> for a non-destructive read (uses <c>BODY.PEEK</c> internally).
|
/// <returns></returns>
|
||||||
/// </param>
|
Task<EmailSyncResult> SyncEmailsAsync(
|
||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
EmailAccount account,
|
||||||
public Task SyncEmailsAsync(
|
string folder = "INBOX",
|
||||||
EmailAccount account,
|
CancellationToken cancel = default);
|
||||||
DateFilter date,
|
|
||||||
string folder = "INBOX",
|
|
||||||
CancellationToken cancel = default);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks a message as seen (read) on the server.
|
/// Marks a message as seen (read) on the server.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public interface IRepository<TEntity> where TEntity : class
|
|||||||
// CREATE
|
// CREATE
|
||||||
Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken cancellationToken = default);
|
Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
Task<IEnumerable<TEntity>> CreateAsync<TDto>(IEnumerable<TDto> dtos, CancellationToken cancellationToken = default);
|
Task<IEnumerable<TEntity>> CreateRangeAsync<TDto>(IEnumerable<TDto> dtos, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
// READ
|
// READ
|
||||||
Task<TEntity?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
Task<TEntity?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|||||||
@@ -23,6 +23,19 @@ public class EmailMappingProfile : Profile
|
|||||||
// EmailAccountDto -> EmailAccount
|
// EmailAccountDto -> EmailAccount
|
||||||
CreateMap<EmailAccount, EmailAccountDto>();
|
CreateMap<EmailAccount, EmailAccountDto>();
|
||||||
CreateMap<EmailAccountModificationDto, EmailAccount>();
|
CreateMap<EmailAccountModificationDto, EmailAccount>();
|
||||||
|
|
||||||
|
// ReceivedEmailDto <-> ReceivedEmail
|
||||||
|
CreateMap<ReceivedEmailDto, ReceivedEmail>()
|
||||||
|
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
||||||
|
.ForMember(dest => dest.Account, opt => opt.Ignore());
|
||||||
|
CreateMap<ReceivedEmail, ReceivedEmailDto>();
|
||||||
|
|
||||||
|
// EmailAttachmentDto <-> EmailAttachment
|
||||||
|
CreateMap<EmailAttachmentDto, EmailAttachment>()
|
||||||
|
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
||||||
|
.ForMember(dest => dest.EmailId, opt => opt.Ignore())
|
||||||
|
.ForMember(dest => dest.Email, opt => opt.Ignore());
|
||||||
|
CreateMap<EmailAttachment, EmailAttachmentDto>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user