Refactor TestEmailTemplateController to use MediatR

Replaced direct service dependency and base class inheritance with MediatR in TestEmailTemplateController. Updated the GetAll endpoint to use a MediatR query and removed obsolete code related to the previous service-based approach. This aligns the controller with CQRS/MediatR best practices.
This commit is contained in:
2026-02-11 12:45:32 +01:00
parent 10f23170fd
commit ec674b6e80

View File

@@ -1,34 +1,22 @@
using DigitalData.Core.Abstraction.Application.DTO; using Microsoft.AspNetCore.Mvc;
using EnvelopeGenerator.Domain.Entities; using MediatR;
using Microsoft.AspNetCore.Mvc; using EnvelopeGenerator.Application.EmailTemplates.Queries;
using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Application.Common.Dto;
using EnvelopeGenerator.Application.Common.Interfaces.Services;
namespace EnvelopeGenerator.Web.Controllers.Test; namespace EnvelopeGenerator.Web.Controllers.Test;
[Obsolete("Use MediatR")] public class TestEmailTemplateController : ControllerBase
public class TestEmailTemplateController : TestControllerBase<IEmailTemplateService, EmailTemplateDto, EmailTemplate, int>
{ {
public TestEmailTemplateController(ILogger<TestEmailTemplateController> logger, IEmailTemplateService service) : base(logger, service) private readonly IMediator _mediator;
public TestEmailTemplateController(IMediator mediator)
{ {
_mediator = mediator;
} }
[HttpGet] [HttpGet]
[Obsolete("Use MediatR")] public virtual async Task<IActionResult> GetAll([FromQuery] ReadEmailTemplateQuery query, CancellationToken cancel)
public virtual async Task<IActionResult> GetAll([FromQuery] string? tempType = null)
{ {
return tempType is null var res = await _mediator.Send(query, cancel);
? await base.GetAll() return Ok(res);
: await _service.ReadByNameAsync((EmailTemplateType)Enum.Parse(typeof(EmailTemplateType), tempType)).ThenAsync(
Success: Ok,
Fail: IActionResult (messages, notices) =>
{
_logger.LogNotice(notices);
return NotFound(messages);
});
} }
[NonAction]
public override Task<IActionResult> GetAll() => base.GetAll();
} }