From 84358ced96566d0d8a7f98432c13dfe21260c74b Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 24 Mar 2026 11:03:28 +0100 Subject: [PATCH] Refactor EndpointsController to use standard MediatR pattern Removed IConfiguration dependency and replaced custom mediator extension methods with standard mediator.Send calls for endpoint commands. Simplified method signatures and removed unused usings. Updated PUT endpoint to accept UpdateEndpointProcedure directly. --- src/ReC.API/Controllers/EndpointsController.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/ReC.API/Controllers/EndpointsController.cs b/src/ReC.API/Controllers/EndpointsController.cs index b486166..c69af98 100644 --- a/src/ReC.API/Controllers/EndpointsController.cs +++ b/src/ReC.API/Controllers/EndpointsController.cs @@ -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.Endpoints.Commands; namespace ReC.API.Controllers; [Route("api/[controller]")] [ApiController] -public class EndpointsController(IMediator mediator, IConfiguration config) : ControllerBase +public class EndpointsController(IMediator mediator) : ControllerBase { /// /// Inserts an endpoint via the ENDPOINT insert procedure. @@ -21,22 +18,21 @@ public class EndpointsController(IMediator mediator, IConfiguration config) : Co [ProducesResponseType(StatusCodes.Status201Created)] public async Task Post([FromBody] InsertEndpointProcedure procedure, CancellationToken cancel) { - var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel); + var id = await mediator.Send(procedure, cancel); return StatusCode(StatusCodes.Status201Created, id); } /// /// Updates an endpoint via the ENDPOINT update procedure. /// - /// ENDPOINT identifier to update. /// UpdateEndpointProcedure payload. /// A token to cancel the operation. /// No content on success. - [HttpPut("{id:long}")] + [HttpPut] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Put([FromRoute] long id, [FromBody] UpdateEndpointProcedure procedure, CancellationToken cancel) + public async Task Put([FromBody] UpdateEndpointProcedure procedure, CancellationToken cancel) { - await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel); + await mediator.Send(procedure, cancel); return NoContent(); } @@ -50,7 +46,7 @@ public class EndpointsController(IMediator mediator, IConfiguration config) : Co [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Delete([FromBody] DeleteEndpointProcedure procedure, CancellationToken cancel) { - await mediator.ExecuteDeleteProcedure(procedure, cancel); + await mediator.Send(procedure, cancel); return NoContent(); } }