Rename SendEmailCommand to PublishEmailCommand

Refactor the codebase to rename `SendEmailCommand` and its associated components to `PublishEmailCommand` for improved clarity and consistency.

- Updated mapping in `EmailMappingProfile.cs` to use `PublishEmailCommand` instead of `SendEmailCommand`.
- Renamed `SendEmailCommand` to `PublishEmailCommand` in `PublishEmailCommand.cs`, including its methods like `WithAttachments`.
- Renamed `SendEmailCommandHandler` to `PublishEmailCommandHandler` and updated its method signature to handle the new command.
- Renamed `SendEmailCommandValidator` to `PublishEmailCommandValidator` and updated validation rules accordingly.
- Updated the `SendEmail` action in `EmailsController.cs` to accept `PublishEmailCommand` instead of `SendEmailCommand`.

These changes ensure consistency across the codebase and better reflect the purpose of the command.
This commit is contained in:
2026-08-06 12:07:39 +02:00
parent 2e69fac250
commit 20de7da93d
4 changed files with 11 additions and 11 deletions

View File

@@ -11,9 +11,9 @@ public class EmailMappingProfile : Profile
{
public EmailMappingProfile()
{
// SendEmailCommand -> Email
// PublishEmailCommand -> Email
// Sender is resolved via MediatR in the handler and set separately after mapping.
CreateMap<SendEmailCommand, EmailContext>()
CreateMap<PublishEmailCommand, EmailContext>()
.ForMember(dest => dest.Sender, opt => opt.Ignore())
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
}

View File

@@ -10,7 +10,7 @@ namespace DigitalData.MessagingService.Application.EmailSending.Commands;
/// <summary>
/// Command to send an email (enqueue to RabbitMQ)
/// </summary>
public record SendEmailCommand : IRequest<Guid>
public record PublishEmailCommand : IRequest<Guid>
{
public required GetSenderQuery Sender { get; init; }
@@ -41,17 +41,17 @@ public record SendEmailCommand : IRequest<Guid>
/// Returns a new command instance with the supplied attachments.
/// Called by the controller after resolving uploaded files.
/// </summary>
public SendEmailCommand WithAttachments(IEnumerable<EmailAttachmentContext> attachments)
public PublishEmailCommand WithAttachments(IEnumerable<EmailAttachmentContext> attachments)
=> this with { Attachments = attachments };
}
/// <summary>
/// Handler for SendEmailCommand
/// Handler for PublishEmailCommand
/// Resolves the sender account via MediatR, maps to SendingEmailEvent and enqueues to RabbitMQ
/// </summary>
public class SendEmailCommandHandler(ISender Sender, ISendingEmailPublisher Publisher, IMapper Mapper) : IRequestHandler<SendEmailCommand, Guid>
public class PublishEmailCommandHandler(ISender Sender, ISendingEmailPublisher Publisher, IMapper Mapper) : IRequestHandler<PublishEmailCommand, Guid>
{
public async Task<Guid> Handle(SendEmailCommand request, CancellationToken cancellationToken)
public async Task<Guid> Handle(PublishEmailCommand request, CancellationToken cancellationToken)
{
var senderAccount = await Sender.Send(request.Sender, cancellationToken)
?? throw new NotFoundException(

View File

@@ -4,11 +4,11 @@ using FluentValidation;
namespace DigitalData.MessagingService.Application.EmailSending.Validators;
/// <summary>
/// Validator for SendEmailCommand
/// Validator for PublishEmailCommand
/// </summary>
public class SendEmailCommandValidator : AbstractValidator<SendEmailCommand>
public class PublishEmailCommandValidator : AbstractValidator<PublishEmailCommand>
{
public SendEmailCommandValidator()
public PublishEmailCommandValidator()
{
RuleFor(x => x.Recipients)
.NotEmpty()

View File

@@ -26,7 +26,7 @@ public class EmailsController(IMediator mediator) : ControllerBase
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> SendEmail(
[FromForm] SendEmailCommand command,
[FromForm] PublishEmailCommand command,
IFormFileCollection? attachments,
CancellationToken cancellationToken)
{