using MediatR; using Microsoft.AspNetCore.Mvc; using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.Endpoints.Commands; namespace ReC.API.Controllers; [Route("api/[controller]")] [ApiController] public class EndpointsController(IMediator mediator) : ControllerBase { /// /// Inserts an endpoint via the ENDPOINT insert procedure. /// /// InsertEndpointProcedure payload. /// A token to cancel the operation. /// The created ENDPOINT identifier. [HttpPost] [ProducesResponseType(StatusCodes.Status201Created)] public async Task Post([FromBody] InsertEndpointCommand procedure, CancellationToken cancel) { var id = await mediator.Send(procedure, cancel); return StatusCode(StatusCodes.Status201Created, id); } /// /// Updates an endpoint via the ENDPOINT update procedure. /// /// The identifier of the ENDPOINT record to update. /// UpdateEndpointProcedure 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] UpdateEndpointDto data, CancellationToken cancel) { await mediator.Send(new UpdateEndpointCommand() { Id = id, Data = data }, cancel); return NoContent(); } /// /// Deletes endpoints via the ENDPOINT delete procedure for the specified id range. /// /// DeleteEndpointProcedure payload (Start, End, Force). /// A token to cancel the operation. /// No content on success. [HttpDelete] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Delete([FromQuery] DeleteEndpointCommand command, CancellationToken cancel) { await mediator.Send(command, cancel); return NoContent(); } }