From 0038169f5ad51a9d6cc38a56b3773f300b789c1e Mon Sep 17 00:00:00 2001 From: Ignacio Gomez Date: Fri, 27 Jun 2025 18:02:24 -0600 Subject: [PATCH] Added new endpoint for variants GetAll --- .../Variant/GetAllFurnitureVariantRequest.cs | 14 +++++++++++ .../UseCases/Inventory/InventoryHandler.cs | 23 +++++++++++++++++-- .../Clients/IInventoryServiceClient.cs | 2 ++ .../Controllers/FurnitureVariantController.cs | 17 ++++++++++---- .../Extensions/ServiceCollectionExtension.cs | 1 + 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantRequest.cs diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantRequest.cs new file mode 100644 index 0000000..ead1729 --- /dev/null +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantRequest.cs @@ -0,0 +1,14 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant +{ + public class GetAllFurnitureVariantRequest : ICommand + { + public bool Validate() => true; + } +} diff --git a/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs b/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs index 52d21d8..81bba52 100644 --- a/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs +++ b/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs @@ -23,7 +23,8 @@ namespace Core.Inventory.Application.UseCases.Inventory IComponentHandler, IComponentHandler, IComponentHandler, - IComponentHandler + IComponentHandler, + IComponentHandler { // FurnitureBase private readonly IFurnitureBasePort _basePort; @@ -315,7 +316,7 @@ namespace Core.Inventory.Application.UseCases.Inventory return; } - var result = await _inventoryDALService.GetFurnitureVariantsByIdsAsync(command.Ids.ToArray()); + var result = await _inventoryDALService.GetFurnitureVariantsByIdsAsync([.. command.Ids], cancellationToken); if (result is null || !result.Any()) { @@ -350,6 +351,24 @@ namespace Core.Inventory.Application.UseCases.Inventory } } + public async ValueTask ExecuteAsync(GetAllFurnitureVariantRequest command, CancellationToken cancellationToken = default) + { + try + { + var result = await _inventoryDALService.GetAllFurnitureVariantAsync(cancellationToken); + if (!result.Any()) + { + _variantPort.NoContentSuccess(); + return; + } + _variantPort.Success([.. result]); + } + catch (Exception ex) + { + ApiResponseHelper.EvaluatePort(ex, _basePort); + } + } + #endregion } } diff --git a/Core.Inventory.External/Clients/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/IInventoryServiceClient.cs index 4a6f83c..08b5807 100644 --- a/Core.Inventory.External/Clients/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/IInventoryServiceClient.cs @@ -47,6 +47,8 @@ namespace Core.Inventory.External.Clients [Patch("/api/v1/FurnitureVariant/{mongoId}/{newStatus}/ChangeStatus")] Task ChangeFurnitureVariantStatusAsync([FromRoute] string mongoId, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); + [Get("/api/v1/FurnitureVariant")] + Task> GetAllFurnitureVariantAsync(CancellationToken cancellationToken = default); #endregion } } diff --git a/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs b/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs index 619026a..8303363 100644 --- a/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs +++ b/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs @@ -12,27 +12,36 @@ namespace Core.Inventory.Service.API.Controllers [ApiController] public class FurnitureVariantController( IComponentHandler getByIdHandler, - IComponentHandler getAllHandler, + IComponentHandler getAllMyModelIdHandler, IComponentHandler createHandler, IComponentHandler updateHandler, IComponentHandler changeStatusHandler, IComponentHandler getByIdsHandler, + IComponentHandler getAllHandler, IFurnitureVariantPort port) : ControllerBase { private readonly IComponentHandler _getByIdHandler = getByIdHandler; - private readonly IComponentHandler _getAllHandler = getAllHandler; + private readonly IComponentHandler _getAllByModelIdHandler = getAllMyModelIdHandler; private readonly IComponentHandler _createHandler = createHandler; private readonly IComponentHandler _updateHandler = updateHandler; private readonly IComponentHandler _changeStatusHandler = changeStatusHandler; private readonly IComponentHandler _getByIdsHandler = getByIdsHandler; + private readonly IComponentHandler _getAllHandler = getAllHandler; private readonly IFurnitureVariantPort _port = port; + [HttpGet("GetAll")] + public async Task GetAllAsync(CancellationToken cancellationToken) + { + await _getAllHandler.ExecuteAsync(new GetAllFurnitureVariantRequest { }, cancellationToken).ConfigureAwait(false); + return _port.ViewModel; + } + [HttpPost("GetAllByModelId")] - public async Task GetAllAsync([FromBody] GetAllFurnitureVariantsByModelIdRequest request, CancellationToken cancellationToken) + public async Task GetAllByModelIdAsync([FromBody] GetAllFurnitureVariantsByModelIdRequest request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request?.ModelId)) return BadRequest("Model ID is required"); - await _getAllHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + await _getAllByModelIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } diff --git a/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs b/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs index 1dca9dd..5d3b226 100644 --- a/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs +++ b/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs @@ -45,6 +45,7 @@ namespace Core.Inventory.Service.API.Extensions services.AddScoped, InventoryHandler>(); services.AddScoped, InventoryHandler>(); services.AddScoped, InventoryHandler>(); + services.AddScoped, InventoryHandler>(); services.AddValidatorsFromAssemblyContaining(); services.AddScoped, CreateFurnitureVariantValidator>();