using MediatR; using Microsoft.AspNetCore.Mvc; using ReC.API.Extensions; using ReC.Application.Common.Procedures.InsertProcedure; using ReC.Application.RecActions.Commands; using ReC.Application.RecActions.Queries; namespace ReC.API.Controllers; [Route("api/[controller]")] [ApiController] public class RecActionController(IMediator mediator, IConfiguration config) : ControllerBase { /// /// Invokes a batch of RecActions for a given profile. /// /// The ID of the profile. /// A token to cancel the operation. /// An HTTP 202 Accepted response indicating the process has been started. [HttpPost("invoke/{profileId}")] [ProducesResponseType(StatusCodes.Status202Accepted)] public async Task Invoke([FromRoute] int profileId, CancellationToken cancel) { await mediator.InvokeBatchRecActionView(profileId, cancel); return Accepted(); } /// /// Invokes a batch of RecActions for a fake/test profile. /// /// A token to cancel the operation. /// An HTTP 202 Accepted response indicating the process has been started. [HttpPost("invoke/fake")] [ProducesResponseType(StatusCodes.Status202Accepted)] public async Task Invoke(CancellationToken cancel) { await mediator.InvokeBatchRecActionView(config.GetFakeProfileId(), cancel); return Accepted(); } #region CRUD /// /// Gets all RecActions for a given profile. /// /// /// A token to cancel the operation. /// A list of RecActions for the specified profile. [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] public async Task Get([FromQuery] ReadRecActionViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel)); /// /// Gets all RecActions for a fake/test profile. /// /// A token to cancel the operation. /// /// A list of RecActions for the fake profile. [HttpGet("fake")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task Get(CancellationToken cancel, [FromQuery] bool invoked = false) => Ok(await mediator.Send(new ReadRecActionViewQuery() { ProfileId = config.GetFakeProfileId(), Invoked = invoked }, cancel)); /// /// Creates a new RecAction. /// /// The command containing the details for the new RecAction. /// A token to cancel the operation. /// An HTTP 201 Created response. [HttpPost] [ProducesResponseType(StatusCodes.Status201Created)] public async Task CreateAction([FromBody] InsertActionProcedure command, CancellationToken cancel) { await mediator.ExecuteInsertProcedure(command, config["AddedWho"], cancel); return StatusCode(StatusCodes.Status201Created); } /// /// Deletes all RecActions associated with a specific profile. /// /// /// A token to cancel the operation. /// An HTTP 204 No Content response upon successful deletion. [HttpDelete] [ProducesResponseType(StatusCodes.Status204NoContent)] [Obsolete("Use the related procedure.")] public async Task Delete([FromQuery] DeleteRecActionsCommand cmd, CancellationToken cancel) { await mediator.Send(cmd, cancel); return NoContent(); } /// /// Deletes all RecActions for a fake/test profile. /// /// A token to cancel the operation. /// An HTTP 204 No Content response upon successful deletion. [HttpDelete("fake")] [ProducesResponseType(StatusCodes.Status204NoContent)] [Obsolete("Use the related procedure.")] public async Task Delete(CancellationToken cancel) { await mediator.Send(new DeleteRecActionsCommand() { ProfileId = config.GetFakeProfileId() }, cancel); return NoContent(); } #endregion CRUD }