From 84cf5c8e4df55c41aae59516849b3526db793b7e Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 10:15:07 +0100 Subject: [PATCH] Add EndpointsController for endpoint CRUD operations Introduced EndpointsController with POST, PUT, and DELETE API endpoints for managing endpoints. Utilizes MediatR to handle insert, update, and delete procedures, and retrieves configuration values as needed. Includes proper routing and response type annotations. --- .../Controllers/EndpointsController.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/ReC.API/Controllers/EndpointsController.cs diff --git a/src/ReC.API/Controllers/EndpointsController.cs b/src/ReC.API/Controllers/EndpointsController.cs new file mode 100644 index 0000000..b486166 --- /dev/null +++ b/src/ReC.API/Controllers/EndpointsController.cs @@ -0,0 +1,56 @@ +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.Endpoints.Commands; + +namespace ReC.API.Controllers; + +[Route("api/[controller]")] +[ApiController] +public class EndpointsController(IMediator mediator, IConfiguration config) : 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] InsertEndpointProcedure procedure, CancellationToken cancel) + { + var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel); + return StatusCode(StatusCodes.Status201Created, id); + } + + /// + /// Updates an endpoint via the ENDPOINT update procedure. + /// + /// ENDPOINT identifier 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] UpdateEndpointProcedure procedure, CancellationToken cancel) + { + await mediator.ExecuteUpdateProcedure(procedure, id, cancel: 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([FromBody] DeleteEndpointProcedure procedure, CancellationToken cancel) + { + await mediator.ExecuteDeleteProcedure(procedure, cancel); + return NoContent(); + } +}