Refactor RecActionController and add CRUD methods

Refactored the `RecActionController` to improve structure and
readability by introducing a `#region CRUD` section. Updated
the `HttpPost` route for invoking actions to `"invoke/{profileId}"`.

Added a new `CreateAction` method to handle action creation
and renamed the `HttpDelete` method from `GetActions` to
`Delete` for clarity. Introduced the `Invoke` method for batch
action invocation. Improved overall code organization and
maintainability.
This commit is contained in:
tekh 2025-12-03 12:54:39 +01:00
parent 1e21d133ae
commit 606a6727f4

View File

@ -11,19 +11,20 @@ namespace ReC.API.Controllers;
[ApiController] [ApiController]
public class RecActionController(IMediator mediator) : ControllerBase public class RecActionController(IMediator mediator) : ControllerBase
{ {
[HttpGet] [HttpPost("invoke/{profileId}")]
public async Task<IActionResult> Get([FromQuery] long profileId, CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery()
{
ProfileId = profileId
}, cancel));
[HttpPost("{profileId}")]
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel) public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
{ {
await mediator.InvokeBatchRecAction(profileId, cancel); await mediator.InvokeBatchRecAction(profileId, cancel);
return Accepted(); return Accepted();
} }
#region CRUD
[HttpGet]
public async Task<IActionResult> Get([FromQuery] long profileId, CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery()
{
ProfileId = profileId
}, cancel));
[HttpPost] [HttpPost]
public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel) public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel)
{ {
@ -60,7 +61,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
} }
[HttpDelete] [HttpDelete]
public async Task<IActionResult> GetActions([FromQuery] int profileId, CancellationToken cancel) public async Task<IActionResult> Delete([FromQuery] int profileId, CancellationToken cancel)
{ {
await mediator.Send(new DeleteRecActionsCommand() await mediator.Send(new DeleteRecActionsCommand()
{ {
@ -69,4 +70,5 @@ public class RecActionController(IMediator mediator) : ControllerBase
return NoContent(); return NoContent();
} }
#endregion CRUD
} }