Refactor EndpointParamsController to use MediatR.Send

Removed IConfiguration dependency and custom MediatR extension methods from EndpointParamsController. All command handling now uses mediator.Send directly, and route/config parameters have been eliminated from endpoints. Cleaned up unused usings and streamlined controller logic.
This commit is contained in:
2026-03-24 11:02:58 +01:00
parent d505c8415e
commit d2e97a2fef

View File

@@ -1,15 +1,12 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.EndpointParams.Commands;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class EndpointParamsController(IMediator mediator, IConfiguration config) : ControllerBase
public class EndpointParamsController(IMediator mediator) : ControllerBase
{
/// <summary>
/// Inserts endpoint parameter records via the ENDPOINT_PARAMS insert procedure.
@@ -21,22 +18,21 @@ public class EndpointParamsController(IMediator mediator, IConfiguration config)
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> Post([FromBody] InsertEndpointParamsProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel);
var id = await mediator.Send(procedure, cancel);
return StatusCode(StatusCodes.Status201Created, id);
}
/// <summary>
/// Updates endpoint parameter records via the ENDPOINT_PARAMS update procedure.
/// </summary>
/// <param name="id">ENDPOINT_PARAMS identifier to update.</param>
/// <param name="procedure">UpdateEndpointParamsProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[HttpPut]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateEndpointParamsProcedure procedure, CancellationToken cancel)
public async Task<IActionResult> Put([FromBody] UpdateEndpointParamsProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
await mediator.Send(procedure, cancel);
return NoContent();
}
@@ -50,7 +46,7 @@ public class EndpointParamsController(IMediator mediator, IConfiguration config)
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromBody] DeleteEndpointParamsProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
await mediator.Send(procedure, cancel);
return NoContent();
}
}