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:
@@ -11,9 +11,9 @@ public class EmailMappingProfile : Profile
|
|||||||
{
|
{
|
||||||
public EmailMappingProfile()
|
public EmailMappingProfile()
|
||||||
{
|
{
|
||||||
// SendEmailCommand -> Email
|
// PublishEmailCommand -> Email
|
||||||
// Sender is resolved via MediatR in the handler and set separately after mapping.
|
// 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.Sender, opt => opt.Ignore())
|
||||||
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace DigitalData.MessagingService.Application.EmailSending.Commands;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Command to send an email (enqueue to RabbitMQ)
|
/// Command to send an email (enqueue to RabbitMQ)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record SendEmailCommand : IRequest<Guid>
|
public record PublishEmailCommand : IRequest<Guid>
|
||||||
{
|
{
|
||||||
public required GetSenderQuery Sender { get; init; }
|
public required GetSenderQuery Sender { get; init; }
|
||||||
|
|
||||||
@@ -41,17 +41,17 @@ public record SendEmailCommand : IRequest<Guid>
|
|||||||
/// Returns a new command instance with the supplied attachments.
|
/// Returns a new command instance with the supplied attachments.
|
||||||
/// Called by the controller after resolving uploaded files.
|
/// Called by the controller after resolving uploaded files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SendEmailCommand WithAttachments(IEnumerable<EmailAttachmentContext> attachments)
|
public PublishEmailCommand WithAttachments(IEnumerable<EmailAttachmentContext> attachments)
|
||||||
=> this with { Attachments = attachments };
|
=> this with { Attachments = attachments };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler for SendEmailCommand
|
/// Handler for PublishEmailCommand
|
||||||
/// Resolves the sender account via MediatR, maps to SendingEmailEvent and enqueues to RabbitMQ
|
/// Resolves the sender account via MediatR, maps to SendingEmailEvent and enqueues to RabbitMQ
|
||||||
/// </summary>
|
/// </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)
|
var senderAccount = await Sender.Send(request.Sender, cancellationToken)
|
||||||
?? throw new NotFoundException(
|
?? throw new NotFoundException(
|
||||||
@@ -4,11 +4,11 @@ using FluentValidation;
|
|||||||
namespace DigitalData.MessagingService.Application.EmailSending.Validators;
|
namespace DigitalData.MessagingService.Application.EmailSending.Validators;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validator for SendEmailCommand
|
/// Validator for PublishEmailCommand
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SendEmailCommandValidator : AbstractValidator<SendEmailCommand>
|
public class PublishEmailCommandValidator : AbstractValidator<PublishEmailCommand>
|
||||||
{
|
{
|
||||||
public SendEmailCommandValidator()
|
public PublishEmailCommandValidator()
|
||||||
{
|
{
|
||||||
RuleFor(x => x.Recipients)
|
RuleFor(x => x.Recipients)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class EmailsController(IMediator mediator) : ControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> SendEmail(
|
public async Task<IActionResult> SendEmail(
|
||||||
[FromForm] SendEmailCommand command,
|
[FromForm] PublishEmailCommand command,
|
||||||
IFormFileCollection? attachments,
|
IFormFileCollection? attachments,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user