using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.EndpointAuth.Commands;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class EndpointAuthController(IMediator mediator, IConfiguration config) : ControllerBase
{
///
/// Inserts an endpoint authentication record via the ENDPOINT_AUTH insert procedure.
///
/// InsertEndpointAuthProcedure payload.
/// A token to cancel the operation.
/// The created ENDPOINT_AUTH identifier.
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task Post([FromBody] InsertEndpointAuthProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel);
return StatusCode(StatusCodes.Status201Created, id);
}
///
/// Updates an endpoint authentication record via the ENDPOINT_AUTH update procedure.
///
/// ENDPOINT_AUTH identifier to update.
/// UpdateEndpointAuthProcedure payload.
/// A token to cancel the operation.
/// No content on success.
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task Put([FromRoute] long id, [FromBody] UpdateEndpointAuthProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
///
/// Deletes endpoint authentication records via the ENDPOINT_AUTH delete procedure for the specified id range.
///
/// DeleteEndpointAuthProcedure payload (Start, End, Force).
/// A token to cancel the operation.
/// No content on success.
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task Delete([FromBody] DeleteEndpointAuthProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
}