Added new endpoint for variants GetAll
This commit is contained in:
parent
24f647f90e
commit
0038169f5a
@ -0,0 +1,14 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="GetAllFurnitureVariantRequest.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant
|
||||
{
|
||||
public class GetAllFurnitureVariantRequest : ICommand
|
||||
{
|
||||
public bool Validate() => true;
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,8 @@ namespace Core.Inventory.Application.UseCases.Inventory
|
||||
IComponentHandler<GetFurnitureVariantByIdRequest>,
|
||||
IComponentHandler<GetAllFurnitureVariantsByModelIdRequest>,
|
||||
IComponentHandler<ChangeFurnitureVariantStatusRequest>,
|
||||
IComponentHandler<GetFurnitureVariantsByIdsRequest>
|
||||
IComponentHandler<GetFurnitureVariantsByIdsRequest>,
|
||||
IComponentHandler<GetAllFurnitureVariantRequest>
|
||||
{
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +47,8 @@ namespace Core.Inventory.External.Clients
|
||||
[Patch("/api/v1/FurnitureVariant/{mongoId}/{newStatus}/ChangeStatus")]
|
||||
Task<FurnitureVariant> ChangeFurnitureVariantStatusAsync([FromRoute] string mongoId, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/api/v1/FurnitureVariant")]
|
||||
Task<IEnumerable<FurnitureVariant>> GetAllFurnitureVariantAsync(CancellationToken cancellationToken = default);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,27 +12,36 @@ namespace Core.Inventory.Service.API.Controllers
|
||||
[ApiController]
|
||||
public class FurnitureVariantController(
|
||||
IComponentHandler<GetFurnitureVariantByIdRequest> getByIdHandler,
|
||||
IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> getAllHandler,
|
||||
IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> getAllMyModelIdHandler,
|
||||
IComponentHandler<CreateFurnitureVariantRequest> createHandler,
|
||||
IComponentHandler<UpdateFurnitureVariantRequest> updateHandler,
|
||||
IComponentHandler<ChangeFurnitureVariantStatusRequest> changeStatusHandler,
|
||||
IComponentHandler<GetFurnitureVariantsByIdsRequest> getByIdsHandler,
|
||||
IComponentHandler<GetAllFurnitureVariantRequest> getAllHandler,
|
||||
IFurnitureVariantPort port) : ControllerBase
|
||||
{
|
||||
private readonly IComponentHandler<GetFurnitureVariantByIdRequest> _getByIdHandler = getByIdHandler;
|
||||
private readonly IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> _getAllHandler = getAllHandler;
|
||||
private readonly IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> _getAllByModelIdHandler = getAllMyModelIdHandler;
|
||||
private readonly IComponentHandler<CreateFurnitureVariantRequest> _createHandler = createHandler;
|
||||
private readonly IComponentHandler<UpdateFurnitureVariantRequest> _updateHandler = updateHandler;
|
||||
private readonly IComponentHandler<ChangeFurnitureVariantStatusRequest> _changeStatusHandler = changeStatusHandler;
|
||||
private readonly IComponentHandler<GetFurnitureVariantsByIdsRequest> _getByIdsHandler = getByIdsHandler;
|
||||
private readonly IComponentHandler<GetAllFurnitureVariantRequest> _getAllHandler = getAllHandler;
|
||||
private readonly IFurnitureVariantPort _port = port;
|
||||
|
||||
[HttpGet("GetAll")]
|
||||
public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _getAllHandler.ExecuteAsync(new GetAllFurnitureVariantRequest { }, cancellationToken).ConfigureAwait(false);
|
||||
return _port.ViewModel;
|
||||
}
|
||||
|
||||
[HttpPost("GetAllByModelId")]
|
||||
public async Task<IActionResult> GetAllAsync([FromBody] GetAllFurnitureVariantsByModelIdRequest request, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ namespace Core.Inventory.Service.API.Extensions
|
||||
services.AddScoped<IComponentHandler<UpdateFurnitureVariantRequest>, InventoryHandler>();
|
||||
services.AddScoped<IComponentHandler<ChangeFurnitureVariantStatusRequest>, InventoryHandler>();
|
||||
services.AddScoped<IComponentHandler<GetFurnitureVariantsByIdsRequest>, InventoryHandler>();
|
||||
services.AddScoped<IComponentHandler<GetAllFurnitureVariantRequest>, InventoryHandler>();
|
||||
|
||||
services.AddValidatorsFromAssemblyContaining<CreateFurnitureVariantValidator>();
|
||||
services.AddScoped<IValidator<CreateFurnitureVariantRequest>, CreateFurnitureVariantValidator>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user