From daff1477be2811d5afbb1c777d19bb0d5680b585 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 24 Mar 2026 12:07:50 +0100 Subject: [PATCH] Refactor PUT endpoints to use id in route and DTO in body Refactored update (PUT) endpoints in multiple controllers to accept the record id as a route parameter and the update data as a DTO in the request body. Updated method signatures, XML documentation, and imports to align with RESTful conventions and improve API clarity. Controller methods now construct command objects using the id and DTO before sending to MediatR. --- src/ReC.API/Controllers/EndpointAuthController.cs | 10 ++++++---- src/ReC.API/Controllers/EndpointParamsController.cs | 10 ++++++---- src/ReC.API/Controllers/EndpointsController.cs | 10 ++++++---- src/ReC.API/Controllers/ProfileController.cs | 10 ++++++---- src/ReC.API/Controllers/RecActionController.cs | 8 +++++--- src/ReC.API/Controllers/ResultController.cs | 13 ++++++------- 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/ReC.API/Controllers/EndpointAuthController.cs b/src/ReC.API/Controllers/EndpointAuthController.cs index 8ac2d27..7ef27dd 100644 --- a/src/ReC.API/Controllers/EndpointAuthController.cs +++ b/src/ReC.API/Controllers/EndpointAuthController.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.AspNetCore.Mvc; +using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.EndpointAuth.Commands; namespace ReC.API.Controllers; @@ -25,14 +26,15 @@ public class EndpointAuthController(IMediator mediator) : ControllerBase /// /// Updates an endpoint authentication record via the ENDPOINT_AUTH update procedure. /// - /// UpdateEndpointAuthProcedure payload. + /// The identifier of the ENDPOINT_AUTH record to update. + /// UpdateEndpointAuthProcedure payload. /// A token to cancel the operation. /// No content on success. - [HttpPut] + [HttpPut("{id:long}")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Put([FromBody] UpdateEndpointAuthCommand procedure, CancellationToken cancel) + public async Task Put([FromRoute] long id, [FromBody] UpdateEndpointAuthDto data, CancellationToken cancel) { - await mediator.Send(procedure, cancel); + await mediator.Send(new UpdateEndpointAuthCommand() { Id = id, Data = data}, cancel); return NoContent(); } diff --git a/src/ReC.API/Controllers/EndpointParamsController.cs b/src/ReC.API/Controllers/EndpointParamsController.cs index f8069fe..8586c02 100644 --- a/src/ReC.API/Controllers/EndpointParamsController.cs +++ b/src/ReC.API/Controllers/EndpointParamsController.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.AspNetCore.Mvc; +using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.EndpointParams.Commands; namespace ReC.API.Controllers; @@ -25,14 +26,15 @@ public class EndpointParamsController(IMediator mediator) : ControllerBase /// /// Updates endpoint parameter records via the ENDPOINT_PARAMS update procedure. /// - /// UpdateEndpointParamsProcedure payload. + /// The identifier of the ENDPOINT_PARAMS record to update. + /// UpdateEndpointParamsProcedure payload. /// A token to cancel the operation. /// No content on success. - [HttpPut] + [HttpPut("{id:long}")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Put([FromBody] UpdateEndpointParamsCommand procedure, CancellationToken cancel) + public async Task Put([FromRoute] long id, [FromBody] UpdateEndpointParamsDto data, CancellationToken cancel) { - await mediator.Send(procedure, cancel); + await mediator.Send(new UpdateEndpointParamsCommand() { Id = id, Data = data }, cancel); return NoContent(); } diff --git a/src/ReC.API/Controllers/EndpointsController.cs b/src/ReC.API/Controllers/EndpointsController.cs index 47f5adb..d68206d 100644 --- a/src/ReC.API/Controllers/EndpointsController.cs +++ b/src/ReC.API/Controllers/EndpointsController.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.AspNetCore.Mvc; +using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.Endpoints.Commands; namespace ReC.API.Controllers; @@ -25,14 +26,15 @@ public class EndpointsController(IMediator mediator) : ControllerBase /// /// Updates an endpoint via the ENDPOINT update procedure. /// - /// UpdateEndpointProcedure payload. + /// The identifier of the ENDPOINT record to update. + /// UpdateEndpointProcedure payload. /// A token to cancel the operation. /// No content on success. - [HttpPut] + [HttpPut("{id:long}")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Put([FromBody] UpdateEndpointCommand procedure, CancellationToken cancel) + public async Task Put([FromRoute] long id, [FromBody] UpdateEndpointDto data, CancellationToken cancel) { - await mediator.Send(procedure, cancel); + await mediator.Send(new UpdateEndpointCommand() { Id = id, Data = data }, cancel); return NoContent(); } diff --git a/src/ReC.API/Controllers/ProfileController.cs b/src/ReC.API/Controllers/ProfileController.cs index 0ce6fcd..ad32e59 100644 --- a/src/ReC.API/Controllers/ProfileController.cs +++ b/src/ReC.API/Controllers/ProfileController.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.AspNetCore.Mvc; +using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.Profile.Commands; using ReC.Application.Profile.Queries; @@ -32,14 +33,15 @@ public class ProfileController(IMediator mediator) : ControllerBase /// /// Updates a profile via the PROFILE update procedure. /// - /// UpdateProfileProcedure payload. + /// The identifier of the PROFILE record to update. + /// UpdateProfileProcedure payload. /// A token to cancel the operation. /// No content on success. - [HttpPut] + [HttpPut("{id:long}")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Put([FromBody] UpdateProfileCommand procedure, CancellationToken cancel) + public async Task Put([FromRoute] long id, [FromBody] UpdateProfileDto data, CancellationToken cancel) { - await mediator.Send(procedure, cancel); + await mediator.Send(new UpdateProfileCommand() { Id = id, Data = data }, cancel); return NoContent(); } diff --git a/src/ReC.API/Controllers/RecActionController.cs b/src/ReC.API/Controllers/RecActionController.cs index 012e9d0..31751f5 100644 --- a/src/ReC.API/Controllers/RecActionController.cs +++ b/src/ReC.API/Controllers/RecActionController.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.AspNetCore.Mvc; +using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.RecActions.Commands; using ReC.Application.RecActions.Queries; @@ -52,14 +53,15 @@ public class RecActionController(IMediator mediator) : ControllerBase /// /// Updates a RecAction via the ACTION update procedure. /// - /// UpdateActionProcedure payload. + /// The identifier of the ACTION record to update. + /// UpdateActionProcedure payload. /// A token to cancel the operation. /// No content on success. [HttpPut("{id:long}")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Update([FromBody] UpdateActionCommand procedure, CancellationToken cancel) + public async Task Update([FromRoute] long id, [FromBody] UpdateActionDto data, CancellationToken cancel) { - await mediator.Send(procedure, cancel); + await mediator.Send(new UpdateActionCommand() { Id = id, Data = data }, cancel); return NoContent(); } diff --git a/src/ReC.API/Controllers/ResultController.cs b/src/ReC.API/Controllers/ResultController.cs index 7926bf9..8fbdd83 100644 --- a/src/ReC.API/Controllers/ResultController.cs +++ b/src/ReC.API/Controllers/ResultController.cs @@ -1,8 +1,6 @@ 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.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.Results.Commands; using ReC.Application.Results.Queries; @@ -39,14 +37,15 @@ public class ResultController(IMediator mediator) : ControllerBase /// /// Updates a RESULT record via the update procedure. /// - /// UpdateResultProcedure payload. + /// The identifier of the RESULT record to update. + /// UpdateResultProcedure payload. /// A token to cancel the operation. /// No content on success. - [HttpPut] + [HttpPut("{id:long}")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Put([FromBody] UpdateResultCommand procedure, CancellationToken cancel) + public async Task Put([FromRoute] long id, [FromBody] UpdateResultDto data, CancellationToken cancel) { - await mediator.Send(procedure, cancel); + await mediator.Send(new UpdateResultCommand() { Id = id, Data = data }, cancel); return NoContent(); }