142 lines
7.0 KiB
C#
142 lines
7.0 KiB
C#
using Asp.Versioning;
|
|
using Core.Blueprint.Application.UsesCases.Mongo.Input;
|
|
using Core.Blueprint.Application.UsesCases.Mongo.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="MongoBlueprintController"/>.
|
|
/// </summary>
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{api-version:apiVersion}/[controller]")]
|
|
[Produces("application/json")]
|
|
[ApiController]
|
|
public class MongoBlueprintController : ControllerBase
|
|
{
|
|
private readonly IComponentHandler<CreateBlueprintRequest> createBlueprintHandler;
|
|
private readonly IComponentHandler<GetAllBlueprintsRequest> getAllBlueprintsHandler;
|
|
private readonly IComponentHandler<GetBlueprintRequest> getBlueprintHandler;
|
|
private readonly IComponentHandler<UpdateBlueprintRequest> updateBlueprintHandler;
|
|
private readonly IComponentHandler<DeleteBlueprintRequest> deleteBlueprintHandler;
|
|
private readonly IMongoPort port;
|
|
|
|
/// <summary>
|
|
/// Handles all services and business rules related to <see cref="MongoBlueprintController"/>.
|
|
/// </summary>
|
|
public MongoBlueprintController(
|
|
IComponentHandler<GetBlueprintRequest> getBlueprintHandler,
|
|
IComponentHandler<GetAllBlueprintsRequest> getAllBlueprintsHandler,
|
|
IComponentHandler<CreateBlueprintRequest> createBlueprintHandler,
|
|
IComponentHandler<UpdateBlueprintRequest> updateBlueprintHandler,
|
|
IComponentHandler<DeleteBlueprintRequest> deleteBlueprintHandler,
|
|
IMongoPort port
|
|
)
|
|
{
|
|
this.createBlueprintHandler = createBlueprintHandler;
|
|
this.updateBlueprintHandler = updateBlueprintHandler;
|
|
this.deleteBlueprintHandler = deleteBlueprintHandler;
|
|
this.getAllBlueprintsHandler = getAllBlueprintsHandler;
|
|
this.getBlueprintHandler = getBlueprintHandler;
|
|
this.port = port;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new blueprint.
|
|
/// </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> CreateBlueprintAsync([FromBody] CreateBlueprintRequest newBlueprint, CancellationToken cancellationToken = default)
|
|
{
|
|
await createBlueprintHandler.ExecuteAsync(newBlueprint, cancellationToken).ConfigureAwait(false);
|
|
return port.ViewModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all blueprints.
|
|
/// </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> GetAllBlueprintsAsync(CancellationToken cancellationToken)
|
|
{
|
|
await getAllBlueprintsHandler.ExecuteAsync(new GetAllBlueprintsRequest { }, cancellationToken).ConfigureAwait(false);
|
|
return port.ViewModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the blueprint 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> GetBlueprintById([FromBody] GetBlueprintRequest request, CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid blueprint identifier"); }
|
|
|
|
await getBlueprintHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
|
|
return port.ViewModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates a full blueprint 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> UpdateBlueprintAsync([FromBody] UpdateBlueprintRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid blueprint identifier"); }
|
|
|
|
await updateBlueprintHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
|
|
return port.ViewModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes a blueprint.
|
|
/// </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> DeleteBlueprintAsync([FromBody] DeleteBlueprintRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrEmpty(request._Id)) { return BadRequest("Invalid blueprint identifier"); }
|
|
|
|
await deleteBlueprintHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
|
|
return port.ViewModel;
|
|
}
|
|
}
|
|
} |