diff --git a/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs b/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs index d576944..e03cbe5 100644 --- a/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs +++ b/src/core/DigitalData.MessagingService.Application/Common/Mappings/EmailMappingProfile.cs @@ -16,7 +16,7 @@ public class EmailMappingProfile : Profile { // PublishEmailCommand -> Email // Sender is resolved via MediatR in the handler and set separately after mapping. - CreateMap() + CreateMap() .ForMember(dest => dest.Sender, opt => opt.Ignore()) .ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments)); diff --git a/src/core/DigitalData.MessagingService.Application/EmailReceiving/Queries/ReadEmailQuery.cs b/src/core/DigitalData.MessagingService.Application/EmailReceiving/Queries/ReadEmailViaImapQuery.cs similarity index 82% rename from src/core/DigitalData.MessagingService.Application/EmailReceiving/Queries/ReadEmailQuery.cs rename to src/core/DigitalData.MessagingService.Application/EmailReceiving/Queries/ReadEmailViaImapQuery.cs index e27dc88..e6e2454 100644 --- a/src/core/DigitalData.MessagingService.Application/EmailReceiving/Queries/ReadEmailQuery.cs +++ b/src/core/DigitalData.MessagingService.Application/EmailReceiving/Queries/ReadEmailViaImapQuery.cs @@ -15,7 +15,7 @@ namespace DigitalData.MessagingService.Application.EmailReceiving.Queries; /// /// Query to fetch emails from an IMAP mailbox. /// -public record ReadEmailQuery : IRequest +public record ReadEmailViaImapQuery : IRequest { /// /// Identifies the email account to use. @@ -28,9 +28,9 @@ public record ReadEmailQuery : IRequest public MailSearchFilter Mail { get; init; } = new(); } -public class ReadEmailQueryHandler(IMapper Mapper, ILogger Logger, IRepository EmailAccountRepo, IReceivedEmailRepository MailRepo, IImapEmailService imapEmailService) : IRequestHandler +public class ReadEmailViaImapQueryHandler(IMapper Mapper, ILogger Logger, IRepository EmailAccountRepo, IReceivedEmailRepository MailRepo, IImapEmailService imapEmailService) : IRequestHandler { - public async Task Handle(ReadEmailQuery request, CancellationToken cancellationToken) + public async Task Handle(ReadEmailViaImapQuery request, CancellationToken cancellationToken) { var accounts = await EmailAccountRepo.FindAsync(request.Account.Id is int id ? x => x.Id == id : x => x.Username == request.Account.Username, cancellationToken: cancellationToken); diff --git a/src/core/DigitalData.MessagingService.Application/EmailReceiving/Validators/FetchEmailsQueryValidator.cs b/src/core/DigitalData.MessagingService.Application/EmailReceiving/Validators/FetchEmailsQueryValidator.cs index 4b49283..e9e7919 100644 --- a/src/core/DigitalData.MessagingService.Application/EmailReceiving/Validators/FetchEmailsQueryValidator.cs +++ b/src/core/DigitalData.MessagingService.Application/EmailReceiving/Validators/FetchEmailsQueryValidator.cs @@ -5,9 +5,9 @@ using FluentValidation; namespace DigitalData.MessagingService.Application.EmailReceiving.Validators; /// -/// Validates a before it is handled by . +/// Validates a before it is handled by . /// -public class FetchEmailsQueryValidator : AbstractValidator +public class FetchEmailsQueryValidator : AbstractValidator { public FetchEmailsQueryValidator() { diff --git a/src/core/DigitalData.MessagingService.Application/EmailSending/Commands/PublishEmailCommand.cs b/src/core/DigitalData.MessagingService.Application/EmailSending/Commands/PublishEmailViaSmtpCommand.cs similarity index 84% rename from src/core/DigitalData.MessagingService.Application/EmailSending/Commands/PublishEmailCommand.cs rename to src/core/DigitalData.MessagingService.Application/EmailSending/Commands/PublishEmailViaSmtpCommand.cs index fcc0f81..9567939 100644 --- a/src/core/DigitalData.MessagingService.Application/EmailSending/Commands/PublishEmailCommand.cs +++ b/src/core/DigitalData.MessagingService.Application/EmailSending/Commands/PublishEmailViaSmtpCommand.cs @@ -15,7 +15,7 @@ namespace DigitalData.MessagingService.Application.EmailSending.Commands; /// /// Command to send an email (enqueue to RabbitMQ) /// -public record PublishEmailCommand : IRequest +public record PublishEmailViaSmtpCommand : IRequest { public required GetEmailAccountQuery Sender { get; init; } @@ -46,7 +46,7 @@ public record PublishEmailCommand : IRequest /// Returns a new command instance with the supplied attachments. /// Called by the controller after resolving uploaded files. /// - public PublishEmailCommand WithAttachments(IEnumerable attachments) + public PublishEmailViaSmtpCommand WithAttachments(IEnumerable attachments) => this with { Attachments = attachments }; } @@ -54,9 +54,9 @@ public record PublishEmailCommand : IRequest /// Handler for PublishEmailCommand /// Resolves the sender account via MediatR, maps to SendingEmailEvent and enqueues to RabbitMQ /// -public class PublishEmailCommandHandler(IRepository Repo, ISendingEmailPublisher Publisher, IMapper Mapper, ILogger Logger) : IRequestHandler +public class PublishEmailViaSmtpCommandHandler(IRepository Repo, ISendingEmailPublisher Publisher, IMapper Mapper, ILogger Logger) : IRequestHandler { - public async Task Handle(PublishEmailCommand request, CancellationToken cancellationToken) + public async Task Handle(PublishEmailViaSmtpCommand request, CancellationToken cancellationToken) { var senderAccounts = await Repo.FindAsync(request.Sender.Id is int id ? x => x.Id == id : x => x.Username == request.Sender.Username, cancellationToken: cancellationToken); diff --git a/src/core/DigitalData.MessagingService.Application/EmailSending/Validators/SendEmailCommandValidator.cs b/src/core/DigitalData.MessagingService.Application/EmailSending/Validators/SendEmailCommandValidator.cs index ac0428e..26bcf45 100644 --- a/src/core/DigitalData.MessagingService.Application/EmailSending/Validators/SendEmailCommandValidator.cs +++ b/src/core/DigitalData.MessagingService.Application/EmailSending/Validators/SendEmailCommandValidator.cs @@ -7,7 +7,7 @@ namespace DigitalData.MessagingService.Application.EmailSending.Validators; /// /// Validator for PublishEmailCommand /// -public class PublishEmailCommandValidator : AbstractValidator +public class PublishEmailCommandValidator : AbstractValidator { public PublishEmailCommandValidator() { diff --git a/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs b/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs index 71181df..ba7b2fc 100644 --- a/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs +++ b/src/presentation/DigitalData.MessagingService.API/Controllers/EmailController.cs @@ -29,7 +29,7 @@ public class EmailController(IMediator mediator) : ControllerBase Uid, } - #region Send + #region SMTP Send /// /// Send an email, optionally with file attachments. /// Omit the attachments field for a plain send. @@ -38,12 +38,12 @@ public class EmailController(IMediator mediator) : ControllerBase /// Optional uploaded files /// Cancellation token /// HTTP 202 Accepted with the queued event ID - [HttpPost] + [HttpPost("smtp")] [Consumes("multipart/form-data")] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task SendEmail( - [FromForm] PublishEmailCommand command, + [FromForm] PublishEmailViaSmtpCommand command, IFormFileCollection? attachments, CancellationToken cancellationToken) { @@ -78,9 +78,9 @@ public class EmailController(IMediator mediator) : ControllerBase return result; } - #endregion Send + #endregion SMTP Send - #region Receive + #region IMAP Receive /// /// Fetch emails from an IMAP mailbox. /// @@ -92,7 +92,7 @@ public class EmailController(IMediator mediator) : ControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task FetchEmails([FromQuery] ReadEmailQuery query, [FromQuery] OnlyFilter? only = null, CancellationToken cancellationToken = default) + public async Task FetchEmails([FromQuery] ReadEmailViaImapQuery query, [FromQuery] OnlyFilter? only = null, CancellationToken cancellationToken = default) { var res = await mediator.Send(query, cancellationToken); @@ -111,7 +111,7 @@ public class EmailController(IMediator mediator) : ControllerBase else return Ok(res); } - #endregion Receive + #endregion IMAP Receive #region IMAP Send /// @@ -122,7 +122,7 @@ public class EmailController(IMediator mediator) : ControllerBase /// Optional uploaded files /// Cancellation token /// HTTP 202 Accepted with the queued event ID - [HttpPost("imap/send")] + [HttpPost("imap")] [Consumes("multipart/form-data")] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status400BadRequest)] @@ -185,7 +185,7 @@ public class EmailController(IMediator mediator) : ControllerBase /// Optional uploaded files /// Cancellation token /// HTTP 202 Accepted with the queued event ID - [HttpPost("oauth2/send")] + [HttpPost("oauth2")] [Consumes("multipart/form-data")] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status400BadRequest)]