From d505c8415e310f75cb5b8d02277ab73ddcced813 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 24 Mar 2026 10:58:43 +0100 Subject: [PATCH] Refactor EndpointAuthController to use MediatR Send Replaced custom procedure execution methods with MediatR's Send method in EndpointAuthController. Removed obsolete using directives and updated the PUT endpoint to no longer require an id route parameter, expecting the id in the payload instead. This streamlines the controller and aligns it with standard MediatR practices. --- src/ReC.API/Controllers/EndpointAuthController.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ReC.API/Controllers/EndpointAuthController.cs b/src/ReC.API/Controllers/EndpointAuthController.cs index af767f3..daa7d1a 100644 --- a/src/ReC.API/Controllers/EndpointAuthController.cs +++ b/src/ReC.API/Controllers/EndpointAuthController.cs @@ -1,8 +1,5 @@ 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.EndpointAuth.Commands; namespace ReC.API.Controllers; @@ -21,22 +18,21 @@ public class EndpointAuthController(IMediator mediator, IConfiguration config) : [ProducesResponseType(StatusCodes.Status201Created)] public async Task Post([FromBody] InsertEndpointAuthProcedure 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 authentication record via the ENDPOINT_AUTH update procedure. /// - /// ENDPOINT_AUTH identifier to update. /// UpdateEndpointAuthProcedure 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] UpdateEndpointAuthProcedure procedure, CancellationToken cancel) + public async Task Put([FromBody] UpdateEndpointAuthProcedure procedure, CancellationToken cancel) { - await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel); + await mediator.Send(procedure, cancel); return NoContent(); } @@ -50,7 +46,7 @@ public class EndpointAuthController(IMediator mediator, IConfiguration config) : [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Delete([FromBody] DeleteEndpointAuthProcedure procedure, CancellationToken cancel) { - await mediator.ExecuteDeleteProcedure(procedure, cancel); + await mediator.Send(procedure, cancel); return NoContent(); } }