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.
This commit is contained in:
2026-03-24 12:07:50 +01:00
parent dcfa47c68d
commit daff1477be
6 changed files with 35 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.EndpointAuth.Commands; using ReC.Application.EndpointAuth.Commands;
namespace ReC.API.Controllers; namespace ReC.API.Controllers;
@@ -25,14 +26,15 @@ public class EndpointAuthController(IMediator mediator) : ControllerBase
/// <summary> /// <summary>
/// Updates an endpoint authentication record via the ENDPOINT_AUTH update procedure. /// Updates an endpoint authentication record via the ENDPOINT_AUTH update procedure.
/// </summary> /// </summary>
/// <param name="procedure">UpdateEndpointAuthProcedure payload.</param> /// <param name="id">The identifier of the ENDPOINT_AUTH record to update.</param>
/// <param name="data">UpdateEndpointAuthProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns> /// <returns>No content on success.</returns>
[HttpPut] [HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromBody] UpdateEndpointAuthCommand procedure, CancellationToken cancel) public async Task<IActionResult> 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(); return NoContent();
} }

View File

@@ -1,5 +1,6 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.EndpointParams.Commands; using ReC.Application.EndpointParams.Commands;
namespace ReC.API.Controllers; namespace ReC.API.Controllers;
@@ -25,14 +26,15 @@ public class EndpointParamsController(IMediator mediator) : ControllerBase
/// <summary> /// <summary>
/// Updates endpoint parameter records via the ENDPOINT_PARAMS update procedure. /// Updates endpoint parameter records via the ENDPOINT_PARAMS update procedure.
/// </summary> /// </summary>
/// <param name="procedure">UpdateEndpointParamsProcedure payload.</param> /// <param name="id">The identifier of the ENDPOINT_PARAMS record to update.</param>
/// <param name="data">UpdateEndpointParamsProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns> /// <returns>No content on success.</returns>
[HttpPut] [HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromBody] UpdateEndpointParamsCommand procedure, CancellationToken cancel) public async Task<IActionResult> 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(); return NoContent();
} }

View File

@@ -1,5 +1,6 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Endpoints.Commands; using ReC.Application.Endpoints.Commands;
namespace ReC.API.Controllers; namespace ReC.API.Controllers;
@@ -25,14 +26,15 @@ public class EndpointsController(IMediator mediator) : ControllerBase
/// <summary> /// <summary>
/// Updates an endpoint via the ENDPOINT update procedure. /// Updates an endpoint via the ENDPOINT update procedure.
/// </summary> /// </summary>
/// <param name="procedure">UpdateEndpointProcedure payload.</param> /// <param name="id">The identifier of the ENDPOINT record to update.</param>
/// <param name="data">UpdateEndpointProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns> /// <returns>No content on success.</returns>
[HttpPut] [HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromBody] UpdateEndpointCommand procedure, CancellationToken cancel) public async Task<IActionResult> 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(); return NoContent();
} }

View File

@@ -1,5 +1,6 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Profile.Commands; using ReC.Application.Profile.Commands;
using ReC.Application.Profile.Queries; using ReC.Application.Profile.Queries;
@@ -32,14 +33,15 @@ public class ProfileController(IMediator mediator) : ControllerBase
/// <summary> /// <summary>
/// Updates a profile via the PROFILE update procedure. /// Updates a profile via the PROFILE update procedure.
/// </summary> /// </summary>
/// <param name="procedure">UpdateProfileProcedure payload.</param> /// <param name="id">The identifier of the PROFILE record to update.</param>
/// <param name="data">UpdateProfileProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns> /// <returns>No content on success.</returns>
[HttpPut] [HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromBody] UpdateProfileCommand procedure, CancellationToken cancel) public async Task<IActionResult> 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(); return NoContent();
} }

View File

@@ -1,5 +1,6 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.RecActions.Commands; using ReC.Application.RecActions.Commands;
using ReC.Application.RecActions.Queries; using ReC.Application.RecActions.Queries;
@@ -52,14 +53,15 @@ public class RecActionController(IMediator mediator) : ControllerBase
/// <summary> /// <summary>
/// Updates a RecAction via the ACTION update procedure. /// Updates a RecAction via the ACTION update procedure.
/// </summary> /// </summary>
/// <param name="procedure">UpdateActionProcedure payload.</param> /// <param name="id">The identifier of the ACTION record to update.</param>
/// <param name="data">UpdateActionProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns> /// <returns>No content on success.</returns>
[HttpPut("{id:long}")] [HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Update([FromBody] UpdateActionCommand procedure, CancellationToken cancel) public async Task<IActionResult> 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(); return NoContent();
} }

View File

@@ -1,8 +1,6 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure; using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Results.Commands; using ReC.Application.Results.Commands;
using ReC.Application.Results.Queries; using ReC.Application.Results.Queries;
@@ -39,14 +37,15 @@ public class ResultController(IMediator mediator) : ControllerBase
/// <summary> /// <summary>
/// Updates a RESULT record via the update procedure. /// Updates a RESULT record via the update procedure.
/// </summary> /// </summary>
/// <param name="procedure">UpdateResultProcedure payload.</param> /// <param name="id">The identifier of the RESULT record to update.</param>
/// <param name="data">UpdateResultProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns> /// <returns>No content on success.</returns>
[HttpPut] [HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromBody] UpdateResultCommand procedure, CancellationToken cancel) public async Task<IActionResult> 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(); return NoContent();
} }