Add procedure-based update and delete endpoints to controller
Refactored RecActionController to support update via a new PUT endpoint using UpdateActionProcedure. Changed DELETE endpoints to use DeleteActionProcedure payloads instead of command objects, removing obsolete attributes. Updated using statements for new procedure types and standardized payload handling for update and delete operations.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReC.API.Extensions;
|
||||
using ReC.Application.Common.Procedures.DeleteProcedure;
|
||||
using ReC.Application.Common.Procedures.InsertProcedure;
|
||||
using ReC.Application.Common.Procedures.UpdateProcedure;
|
||||
using ReC.Application.RecActions.Commands;
|
||||
using ReC.Application.RecActions.Queries;
|
||||
|
||||
@@ -79,33 +81,48 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all RecActions associated with a specific profile.
|
||||
/// Updates a RecAction via the ACTION update procedure.
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
/// <param name="id">RecAction identifier to update.</param>
|
||||
/// <param name="procedure">UpdateActionProcedure payload.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
|
||||
[HttpDelete]
|
||||
/// <returns>No content on success.</returns>
|
||||
[HttpPut("{id:long}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[Obsolete("Use the related procedure.")]
|
||||
public async Task<IActionResult> Delete([FromQuery] DeleteRecActionsCommand cmd, CancellationToken cancel)
|
||||
public async Task<IActionResult> UpdateAction([FromRoute] long id, [FromBody] UpdateActionProcedure procedure, CancellationToken cancel)
|
||||
{
|
||||
await mediator.Send(cmd, cancel);
|
||||
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all RecActions for a fake/test profile.
|
||||
/// Deletes RecActions via the ACTION delete procedure for the specified id range.
|
||||
/// </summary>
|
||||
/// <param name="procedure">DeleteActionProcedure payload (Start, End, Force).</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
|
||||
[HttpDelete]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> Delete([FromBody] DeleteActionProcedure procedure, CancellationToken cancel)
|
||||
{
|
||||
await mediator.ExecuteDeleteProcedure(procedure, cancel);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes RecActions for a fake/test profile via the ACTION delete procedure.
|
||||
/// </summary>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
|
||||
[HttpDelete("fake")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[Obsolete("Use the related procedure.")]
|
||||
public async Task<IActionResult> Delete(CancellationToken cancel)
|
||||
{
|
||||
await mediator.Send(new DeleteRecActionsCommand()
|
||||
await mediator.ExecuteDeleteProcedure(new DeleteActionProcedure
|
||||
{
|
||||
ProfileId = config.GetFakeProfileId()
|
||||
Start = config.GetFakeProfileId(),
|
||||
End = config.GetFakeProfileId(),
|
||||
Force = false
|
||||
}, cancel);
|
||||
|
||||
return NoContent();
|
||||
|
||||
Reference in New Issue
Block a user