Core.Blueprint.Service/Core.Blueprint.Service.API/Controllers/SQLUserProjectController.cs
Sergio Matias Urquin b2635193dc Add project files.
2025-04-29 18:44:41 -06:00

142 lines
7.1 KiB
C#

using Asp.Versioning;
using Core.Blueprint.Application.UsesCases.SQL.Input;
using Core.Blueprint.Application.UsesCases.SQL.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Cerberos.Service.API.Controllers
{
/// <summary>
/// Handles all services and business rules related to <see cref="SQLUserProjectController"/>.
/// </summary>
[ApiVersion("1.0")]
[Route("api/v{api-version:apiVersion}/[controller]")]
[Produces("application/json")]
[ApiController]
public class SQLUserProjectController : ControllerBase
{
private readonly IComponentHandler<CreateUserProjectRequest> createUserProjectHandler;
private readonly IComponentHandler<GetAllUserProjectsRequest> getAllUserProjectsHandler;
private readonly IComponentHandler<GetUserProjectRequest> getUserProjectHandler;
private readonly IComponentHandler<UpdateUserProjectRequest> updateUserProjectHandler;
private readonly IComponentHandler<DeleteUserProjectRequest> deleteUserProjectStatusHandler;
private readonly ISQLPort port;
/// <summary>
/// Handles all services and business rules related to <see cref="SQLUserProjectController"/>.
/// </summary>
public SQLUserProjectController(
IComponentHandler<GetUserProjectRequest> getUserProjectHandler,
IComponentHandler<GetAllUserProjectsRequest> getAllUserProjectsHandler,
IComponentHandler<CreateUserProjectRequest> createUserProjectHandler,
IComponentHandler<UpdateUserProjectRequest> updateUserProjectHandler,
IComponentHandler<DeleteUserProjectRequest> deleteUserProjectStatusHandler,
ISQLPort port
)
{
this.createUserProjectHandler = createUserProjectHandler;
this.updateUserProjectHandler = updateUserProjectHandler;
this.deleteUserProjectStatusHandler = deleteUserProjectStatusHandler;
this.getAllUserProjectsHandler = getAllUserProjectsHandler;
this.getUserProjectHandler = getUserProjectHandler;
this.port = port;
}
/// <summary>
/// Creates a new UserProject.
/// </summary>
[HttpPost("Create")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> CreateUserProjectAsync([FromBody] CreateUserProjectRequest newUserProject, CancellationToken cancellationToken = default)
{
await createUserProjectHandler.ExecuteAsync(newUserProject, cancellationToken).ConfigureAwait(false);
return port.ViewModel;
}
/// <summary>
/// Gets all UserProjects.
/// </summary>
[HttpGet("GetAll")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> GetAllUserProjectsAsync(CancellationToken cancellationToken)
{
await getAllUserProjectsHandler.ExecuteAsync(new GetAllUserProjectsRequest { }, cancellationToken).ConfigureAwait(false);
return port.ViewModel;
}
/// <summary>
/// Gets the UserProject by identifier.
/// </summary>
[HttpPost]
[Route("GetById")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetUserProjectById([FromBody] GetUserProjectRequest request, CancellationToken cancellationToken)
{
if (request.Id <= 0) { return BadRequest("Invalid UserProject identifier"); }
await getUserProjectHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
return port.ViewModel;
}
/// <summary>
/// Updates a full UserProject by identifier.
/// </summary>
[HttpPut("Update")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateUserProjectAsync([FromBody] UpdateUserProjectRequest request, CancellationToken cancellationToken = default)
{
if (request.Id <= 0) { return BadRequest("Invalid UserProject identifier"); }
await updateUserProjectHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
return port.ViewModel;
}
/// <summary>
/// Deletes a UserProject.
/// </summary>
[HttpDelete]
[Route("Delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteUserProjectStatusAsync([FromBody] DeleteUserProjectRequest request,
CancellationToken cancellationToken)
{
if (request.Id <= 0) { return BadRequest("Invalid UserProject identifier"); }
await deleteUserProjectStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
return port.ViewModel;
}
}
}