Renamed CreateAction to Create and UpdateAction to Update in RecActionController to improve naming consistency. No changes to method logic or signatures.
131 lines
5.4 KiB
C#
131 lines
5.4 KiB
C#
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;
|
|
|
|
namespace ReC.API.Controllers;
|
|
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class RecActionController(IMediator mediator, IConfiguration config) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Invokes a batch of RecActions for a given profile.
|
|
/// </summary>
|
|
/// <param name="profileId">The ID of the profile.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
|
|
[HttpPost("invoke/{profileId}")]
|
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
|
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
|
|
{
|
|
await mediator.InvokeBatchRecActionView(profileId, cancel);
|
|
return Accepted();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invokes a batch of RecActions for a fake/test profile.
|
|
/// </summary>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
|
|
[HttpPost("invoke/fake")]
|
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
|
public async Task<IActionResult> Invoke(CancellationToken cancel)
|
|
{
|
|
await mediator.InvokeBatchRecActionView(config.GetFakeProfileId(), cancel);
|
|
return Accepted();
|
|
}
|
|
|
|
#region CRUD
|
|
/// <summary>
|
|
/// Gets all RecActions for a given profile.
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>A list of RecActions for the specified profile.</returns>
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> Get([FromQuery] ReadRecActionViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
|
|
|
|
/// <summary>
|
|
/// Gets all RecActions for a fake/test profile.
|
|
/// </summary>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <param name="invoked"></param>
|
|
/// <returns>A list of RecActions for the fake profile.</returns>
|
|
[HttpGet("fake")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> Get(CancellationToken cancel, [FromQuery] bool invoked = false) => Ok(await mediator.Send(new ReadRecActionViewQuery()
|
|
{
|
|
ProfileId = config.GetFakeProfileId(),
|
|
Invoked = invoked
|
|
}, cancel));
|
|
|
|
/// <summary>
|
|
/// Creates a new RecAction.
|
|
/// </summary>
|
|
/// <param name="command">The command containing the details for the new RecAction.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>An HTTP 201 Created response.</returns>
|
|
[HttpPost]
|
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
|
public async Task<IActionResult> Create([FromBody] InsertActionProcedure command, CancellationToken cancel)
|
|
{
|
|
await mediator.ExecuteInsertProcedure(command, config["AddedWho"], cancel);
|
|
|
|
return StatusCode(StatusCodes.Status201Created);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates a RecAction via the ACTION update procedure.
|
|
/// </summary>
|
|
/// <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>No content on success.</returns>
|
|
[HttpPut("{id:long}")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
public async Task<IActionResult> Update([FromRoute] long id, [FromBody] UpdateActionProcedure procedure, CancellationToken cancel)
|
|
{
|
|
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
|
|
return NoContent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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)]
|
|
public async Task<IActionResult> Delete(CancellationToken cancel)
|
|
{
|
|
await mediator.ExecuteDeleteProcedure(new DeleteActionProcedure
|
|
{
|
|
Start = config.GetFakeProfileId(),
|
|
End = config.GetFakeProfileId(),
|
|
Force = false
|
|
}, cancel);
|
|
|
|
return NoContent();
|
|
}
|
|
#endregion CRUD
|
|
} |