68 lines
3.2 KiB
C#
68 lines
3.2 KiB
C#
using Asp.Versioning;
|
|
using Core.Inventory.Application.UseCases.Inventory.Input.Base;
|
|
using Core.Inventory.Application.UseCases.Inventory.Ports;
|
|
using Lib.Architecture.BuildingBlocks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Core.Inventory.Service.API.Controllers
|
|
{
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{api-version:apiVersion}/[controller]")]
|
|
[Produces("application/json")]
|
|
[ApiController]
|
|
public class FurnitureBaseController(
|
|
IComponentHandler<GetFurnitureBaseByIdRequest> getByIdHandler,
|
|
IComponentHandler<GetAllFurnitureBaseRequest> getAllHandler,
|
|
IComponentHandler<CreateFurnitureBaseRequest> createHandler,
|
|
IComponentHandler<UpdateFurnitureBaseRequest> updateHandler,
|
|
IComponentHandler<ChangeFurnitureBaseStatusRequest> changeStatusHandler,
|
|
IFurnitureBasePort port) : ControllerBase
|
|
{
|
|
private readonly IComponentHandler<GetFurnitureBaseByIdRequest> _getByIdHandler = getByIdHandler;
|
|
private readonly IComponentHandler<GetAllFurnitureBaseRequest> _getAllHandler = getAllHandler;
|
|
private readonly IComponentHandler<CreateFurnitureBaseRequest> _createHandler = createHandler;
|
|
private readonly IComponentHandler<UpdateFurnitureBaseRequest> _updateHandler = updateHandler;
|
|
private readonly IComponentHandler<ChangeFurnitureBaseStatusRequest> _changeStatusHandler = changeStatusHandler;
|
|
private readonly IFurnitureBasePort _port = port;
|
|
|
|
[HttpGet("GetAll")]
|
|
public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken)
|
|
{
|
|
await _getAllHandler.ExecuteAsync(new GetAllFurnitureBaseRequest { }, cancellationToken).ConfigureAwait(false);
|
|
return _port.ViewModel;
|
|
}
|
|
|
|
[HttpPost("GetById")]
|
|
public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture base identifier is required");
|
|
|
|
await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
return _port.ViewModel;
|
|
}
|
|
|
|
[HttpPost("Create")]
|
|
public async Task<IActionResult> CreateAsync([FromBody] CreateFurnitureBaseRequest request, CancellationToken cancellationToken)
|
|
{
|
|
await _createHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
return _port.ViewModel;
|
|
}
|
|
|
|
[HttpPut("Update")]
|
|
public async Task<IActionResult> UpdateAsync([FromBody] UpdateFurnitureBaseRequest request, CancellationToken cancellationToken)
|
|
{
|
|
await _updateHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
return _port.ViewModel;
|
|
}
|
|
|
|
[HttpPatch("ChangeStatus")]
|
|
public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture base identifier is required");
|
|
|
|
await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
|
|
return _port.ViewModel;
|
|
}
|
|
}
|
|
}
|