using Asp.Versioning; using Core.Inventory.Application.UseCases.Inventory.Input; 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 : ControllerBase { private readonly IComponentHandler _getByIdHandler; private readonly IComponentHandler _getAllHandler; private readonly IComponentHandler _createHandler; private readonly IComponentHandler _updateHandler; private readonly IComponentHandler _changeStatusHandler; private readonly IFurnitureBasePort _port; public FurnitureBaseController( IComponentHandler getByIdHandler, IComponentHandler getAllHandler, IComponentHandler createHandler, IComponentHandler updateHandler, IComponentHandler changeStatusHandler, IFurnitureBasePort port) { _getByIdHandler= getByIdHandler; _getAllHandler= getAllHandler; _createHandler= createHandler; _updateHandler= updateHandler; _changeStatusHandler= changeStatusHandler; _port= port; } [HttpGet("GetAll")] public async Task GetAllAsync(CancellationToken cancellationToken) { await _getAllHandler.ExecuteAsync(new GetAllFurnitureBaseRequest { }, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } [HttpPost("GetById")] public async Task GetByIdAsync([FromBody] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture base identifier is required"); await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } [HttpPost("Create")] public async Task CreateAsync([FromBody] CreateFurnitureBaseRequest request, CancellationToken cancellationToken) { await _createHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } [HttpPut("Update")] public async Task UpdateAsync([FromBody] UpdateFurnitureBaseRequest request, CancellationToken cancellationToken) { await _updateHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } [HttpPatch("ChangeStatus")] public async Task ChangeStatusAsync([FromBody] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture base identifier is required"); await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } } }