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:
@@ -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
|
||||
/// <summary>
|
||||
/// Updates an endpoint via the ENDPOINT update procedure.
|
||||
/// </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>
|
||||
/// <returns>No content on success.</returns>
|
||||
[HttpPut]
|
||||
[HttpPut("{id:long}")]
|
||||
[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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user