using MediatR; using Microsoft.AspNetCore.Mvc; using ReC.Application.Common.Procedures.UpdateProcedure.Dto; using ReC.Application.Profile.Commands; using ReC.Application.Profile.Queries; namespace ReC.API.Controllers; [Route("api/[controller]")] [ApiController] public class ProfileController(IMediator mediator) : ControllerBase { [HttpGet] public async Task Get([FromQuery] ReadProfileViewQuery query, CancellationToken cancel) { return Ok(await mediator.Send(query, cancel)); } /// /// Inserts a profile via the PROFILE insert procedure. /// /// InsertProfileProcedure payload. /// A token to cancel the operation. /// The created profile identifier. [HttpPost] [ProducesResponseType(StatusCodes.Status201Created)] public async Task Post([FromBody] InsertProfileCommand procedure, CancellationToken cancel) { var id = await mediator.Send(procedure, cancel); return CreatedAtAction(nameof(Get), new { id }, id); } /// /// Updates a profile via the PROFILE update procedure. /// /// The identifier of the PROFILE record to update. /// UpdateProfileProcedure 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] UpdateProfileDto data, CancellationToken cancel) { await mediator.Send(new UpdateProfileCommand() { Id = id, Data = data }, cancel); return NoContent(); } /// /// Deletes profile records via the PROFILE delete procedure for the specified id range. /// /// DeleteProfileProcedure payload (Start, End, Force). /// A token to cancel the operation. /// No content on success. [HttpDelete] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Delete([FromQuery] DeleteProfileCommand command, CancellationToken cancel) { await mediator.Send(command, cancel); return NoContent(); } }