diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/ChangeFurnitureBaseStatusRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Base/ChangeFurnitureBaseStatusRequest.cs similarity index 77% rename from Core.Inventory.Application/UseCases/Inventory/Input/ChangeFurnitureBaseStatusRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Base/ChangeFurnitureBaseStatusRequest.cs index 56b60c2..ddbe2f9 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/ChangeFurnitureBaseStatusRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Base/ChangeFurnitureBaseStatusRequest.cs @@ -7,19 +7,19 @@ using Core.Blueprint.Mongo; using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Base { /// /// Command to change the status of a furniture base model. /// public class ChangeFurnitureBaseStatusRequest : Notificator, ICommand { - public string Id { get; set; } = null!; + public string MongoId { get; set; } = null!; public StatusEnum Status { get; set; } public bool Validate() { - return !string.IsNullOrWhiteSpace(Id); + return !string.IsNullOrWhiteSpace(MongoId); } } } diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/CreateFurnitureBaseRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Base/CreateFurnitureBaseRequest.cs similarity index 94% rename from Core.Inventory.Application/UseCases/Inventory/Input/CreateFurnitureBaseRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Base/CreateFurnitureBaseRequest.cs index e1aad86..9c6c7bd 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/CreateFurnitureBaseRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Base/CreateFurnitureBaseRequest.cs @@ -6,7 +6,7 @@ using Core.Inventory.Application.UseCases.Inventory.Input.Common; using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Base { /// /// Command for creating a new furniture base entity. diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/GetAllFurnitureBaseRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Base/GetAllFurnitureBaseRequest.cs similarity index 85% rename from Core.Inventory.Application/UseCases/Inventory/Input/GetAllFurnitureBaseRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Base/GetAllFurnitureBaseRequest.cs index ec3b772..d51af13 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/GetAllFurnitureBaseRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Base/GetAllFurnitureBaseRequest.cs @@ -5,7 +5,7 @@ // *********************************************************************** using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Base { public class GetAllFurnitureBaseRequest : ICommand { diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/GetFurnitureBaseByIdRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Base/GetFurnitureBaseByIdRequest.cs similarity index 74% rename from Core.Inventory.Application/UseCases/Inventory/Input/GetFurnitureBaseByIdRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Base/GetFurnitureBaseByIdRequest.cs index f59d0c1..79c66f0 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/GetFurnitureBaseByIdRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Base/GetFurnitureBaseByIdRequest.cs @@ -5,18 +5,18 @@ // *********************************************************************** using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Base { /// /// Query to retrieve a furniture base by its identifier. /// public class GetFurnitureBaseByIdRequest : Notificator, ICommand { - public string Id { get; set; } = null!; + public string MongoId { get; set; } = null!; public bool Validate() { - return !string.IsNullOrWhiteSpace(Id); + return !string.IsNullOrWhiteSpace(MongoId); } } } diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/UpdateFurnitureBaseRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Base/UpdateFurnitureBaseRequest.cs similarity index 95% rename from Core.Inventory.Application/UseCases/Inventory/Input/UpdateFurnitureBaseRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Base/UpdateFurnitureBaseRequest.cs index 19964ce..9918674 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/UpdateFurnitureBaseRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Base/UpdateFurnitureBaseRequest.cs @@ -6,7 +6,7 @@ using Core.Inventory.Application.UseCases.Inventory.Input.Common; using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Base { /// /// Command for updating an existing furniture base entity. diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/ChangeFurnitureVariantStatusRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/ChangeFurnitureVariantStatusRequest.cs similarity index 77% rename from Core.Inventory.Application/UseCases/Inventory/Input/ChangeFurnitureVariantStatusRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Variant/ChangeFurnitureVariantStatusRequest.cs index b8c28b9..616ef17 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/ChangeFurnitureVariantStatusRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/ChangeFurnitureVariantStatusRequest.cs @@ -6,19 +6,19 @@ using Core.Blueprint.Mongo; using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant { /// /// Command to change the status of a furniture variant. /// public class ChangeFurnitureVariantStatusRequest : Notificator, ICommand { - public string Id { get; set; } = null!; + public string MongoId { get; set; } = null!; public StatusEnum Status { get; set; } public bool Validate() { - return !string.IsNullOrWhiteSpace(Id); + return !string.IsNullOrWhiteSpace(MongoId); } } } diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/CreateFurnitureVariantRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/CreateFurnitureVariantRequest.cs similarity index 94% rename from Core.Inventory.Application/UseCases/Inventory/Input/CreateFurnitureVariantRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Variant/CreateFurnitureVariantRequest.cs index 926feda..62188ba 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/CreateFurnitureVariantRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/CreateFurnitureVariantRequest.cs @@ -5,7 +5,7 @@ // *********************************************************************** using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant { public class CreateFurnitureVariantRequest : Notificator, ICommand { diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/GetAllFurnitureVariantsByModelIdRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantsByModelIdRequest.cs similarity index 88% rename from Core.Inventory.Application/UseCases/Inventory/Input/GetAllFurnitureVariantsByModelIdRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantsByModelIdRequest.cs index 7b5b1d2..cb9ad7b 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/GetAllFurnitureVariantsByModelIdRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetAllFurnitureVariantsByModelIdRequest.cs @@ -5,7 +5,7 @@ // *********************************************************************** using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant { public class GetAllFurnitureVariantsByModelIdRequest : Notificator, ICommand { diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/GetFurnitureVariantByIdRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetFurnitureVariantByIdRequest.cs similarity index 70% rename from Core.Inventory.Application/UseCases/Inventory/Input/GetFurnitureVariantByIdRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetFurnitureVariantByIdRequest.cs index a8bcdb5..ea21654 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/GetFurnitureVariantByIdRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetFurnitureVariantByIdRequest.cs @@ -5,15 +5,15 @@ // *********************************************************************** using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant { public class GetFurnitureVariantByIdRequest : Notificator, ICommand { - public string Id { get; set; } = null!; + public string MongoId { get; set; } = null!; public bool Validate() { - return !string.IsNullOrWhiteSpace(Id); + return !string.IsNullOrWhiteSpace(MongoId); } } } diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetFurnitureVariantsByIdsRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetFurnitureVariantsByIdsRequest.cs new file mode 100644 index 0000000..74dfdfc --- /dev/null +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/GetFurnitureVariantsByIdsRequest.cs @@ -0,0 +1,22 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant +{ + /// + /// Request to retrieve multiple furniture variants by their identifiers. + /// + public class GetFurnitureVariantsByIdsRequest : Notificator, ICommand + { + public string[] Ids { get; set; } = []; + + public bool Validate() + { + return Ids is not null && Ids.Length > 0 && Ids.All(id => !string.IsNullOrWhiteSpace(id)); + } + } +} diff --git a/Core.Inventory.Application/UseCases/Inventory/Input/UpdateFurnitureVariantRequest.cs b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/UpdateFurnitureVariantRequest.cs similarity index 95% rename from Core.Inventory.Application/UseCases/Inventory/Input/UpdateFurnitureVariantRequest.cs rename to Core.Inventory.Application/UseCases/Inventory/Input/Variant/UpdateFurnitureVariantRequest.cs index da98059..d6e3d60 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Input/UpdateFurnitureVariantRequest.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Input/Variant/UpdateFurnitureVariantRequest.cs @@ -6,7 +6,7 @@ using Lib.Architecture.BuildingBlocks; -namespace Core.Inventory.Application.UseCases.Inventory.Input +namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant { /// /// Command for updating an existing furniture variant. diff --git a/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs b/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs index bbfc032..52d21d8 100644 --- a/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs +++ b/Core.Inventory.Application/UseCases/Inventory/InventoryHandler.cs @@ -1,5 +1,7 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using Core.Inventory.Application.UseCases.Inventory.Ports; +using Core.Inventory.Application.UseCases.Inventory.Validator.Variant; using Core.Inventory.External.Clients; using Core.Inventory.External.Clients.Requests; using FluentValidation; @@ -20,7 +22,8 @@ namespace Core.Inventory.Application.UseCases.Inventory IComponentHandler, IComponentHandler, IComponentHandler, - IComponentHandler + IComponentHandler, + IComponentHandler { // FurnitureBase private readonly IFurnitureBasePort _basePort; @@ -161,7 +164,7 @@ namespace Core.Inventory.Application.UseCases.Inventory try { ArgumentNullException.ThrowIfNull(command); - var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.Id, cancellationToken); + var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.MongoId, cancellationToken); if (result is null) { _basePort.NoContentSuccess(); @@ -186,7 +189,7 @@ namespace Core.Inventory.Application.UseCases.Inventory return; } - var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.Id, command.Status, cancellationToken); + var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.MongoId, command.Status, cancellationToken); _basePort.Success(result); } catch (Exception ex) @@ -267,7 +270,7 @@ namespace Core.Inventory.Application.UseCases.Inventory try { ArgumentNullException.ThrowIfNull(command); - var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.Id, cancellationToken); + var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.MongoId, cancellationToken); if (result is null) { _variantPort.NoContentSuccess(); @@ -300,6 +303,34 @@ namespace Core.Inventory.Application.UseCases.Inventory } } + public async ValueTask ExecuteAsync(GetFurnitureVariantsByIdsRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + if (!command.IsValid(new GetFurnitureVariantsByIdsValidator())) + { + _variantPort.ValidationErrors(command.Notifications); + return; + } + + var result = await _inventoryDALService.GetFurnitureVariantsByIdsAsync(command.Ids.ToArray()); + + if (result is null || !result.Any()) + { + _variantPort.NoContentSuccess(); + return; + } + + _variantPort.Success([.. result]); + } + catch (Exception ex) + { + ApiResponseHelper.EvaluatePort(ex, _variantPort); + } + } + public async ValueTask ExecuteAsync(ChangeFurnitureVariantStatusRequest command, CancellationToken cancellationToken = default) { try @@ -310,7 +341,7 @@ namespace Core.Inventory.Application.UseCases.Inventory _variantPort.ValidationErrors(command.Notifications); return; } - var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.Id, command.Status, cancellationToken); + var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.MongoId, command.Status, cancellationToken); _variantPort.Success(result); } catch (Exception ex) diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/ChangeFurnitureBaseStatusValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/ChangeFurnitureBaseStatusValidator.cs similarity index 80% rename from Core.Inventory.Application/UseCases/Inventory/Validator/ChangeFurnitureBaseStatusValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Base/ChangeFurnitureBaseStatusValidator.cs index 7220c93..82ea9d3 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/ChangeFurnitureBaseStatusValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/ChangeFurnitureBaseStatusValidator.cs @@ -1,13 +1,13 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base { public class ChangeFurnitureBaseStatusValidator : AbstractValidator { public ChangeFurnitureBaseStatusValidator() { - RuleFor(x => x.Id) + RuleFor(x => x.MongoId) .NotEmpty().WithMessage("Id is required."); RuleFor(x => x.Status) diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/CreateFurnitureBaseValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/CreateFurnitureBaseValidator.cs similarity index 93% rename from Core.Inventory.Application/UseCases/Inventory/Validator/CreateFurnitureBaseValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Base/CreateFurnitureBaseValidator.cs index ca24a1b..056089e 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/CreateFurnitureBaseValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/CreateFurnitureBaseValidator.cs @@ -3,11 +3,11 @@ // Core.Inventory // // *********************************************************************** -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; using Core.Inventory.Application.UseCases.Inventory.Validator.Common; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base { public class CreateFurnitureBaseValidator : AbstractValidator { diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/GetFurnitureBaseByIdValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/GetFurnitureBaseByIdValidator.cs similarity index 74% rename from Core.Inventory.Application/UseCases/Inventory/Validator/GetFurnitureBaseByIdValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Base/GetFurnitureBaseByIdValidator.cs index af79464..bc85849 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/GetFurnitureBaseByIdValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/GetFurnitureBaseByIdValidator.cs @@ -1,13 +1,13 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base { public class GetFurnitureBaseByIdValidator : AbstractValidator { public GetFurnitureBaseByIdValidator() { - RuleFor(x => x.Id) + RuleFor(x => x.MongoId) .NotEmpty().WithMessage("Id is required."); } } diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/UpdateFurnitureBaseValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/UpdateFurnitureBaseValidator.cs similarity index 90% rename from Core.Inventory.Application/UseCases/Inventory/Validator/UpdateFurnitureBaseValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Base/UpdateFurnitureBaseValidator.cs index a8860ce..5c7c546 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/UpdateFurnitureBaseValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Base/UpdateFurnitureBaseValidator.cs @@ -1,8 +1,8 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; using Core.Inventory.Application.UseCases.Inventory.Validator.Common; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base { public class UpdateFurnitureBaseValidator : AbstractValidator { diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/ChangeFurnitureVariantStatusValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/ChangeFurnitureVariantStatusValidator.cs similarity index 79% rename from Core.Inventory.Application/UseCases/Inventory/Validator/ChangeFurnitureVariantStatusValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Variant/ChangeFurnitureVariantStatusValidator.cs index 31ccbd9..d6f73d4 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/ChangeFurnitureVariantStatusValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/ChangeFurnitureVariantStatusValidator.cs @@ -1,13 +1,13 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant { public class ChangeFurnitureVariantStatusValidator : AbstractValidator { public ChangeFurnitureVariantStatusValidator() { - RuleFor(x => x.Id) + RuleFor(x => x.MongoId) .NotEmpty().WithMessage("Id is required."); RuleFor(x => x.Status) diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/CreateFurnitureVariantValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/CreateFurnitureVariantValidator.cs similarity index 93% rename from Core.Inventory.Application/UseCases/Inventory/Validator/CreateFurnitureVariantValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Variant/CreateFurnitureVariantValidator.cs index 62bf54b..2d7c6f9 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/CreateFurnitureVariantValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/CreateFurnitureVariantValidator.cs @@ -1,7 +1,7 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant { public class CreateFurnitureVariantValidator : AbstractValidator { diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/GetAllFurnitureVariantsByModelIdValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetAllFurnitureVariantsByModelIdValidator.cs similarity index 83% rename from Core.Inventory.Application/UseCases/Inventory/Validator/GetAllFurnitureVariantsByModelIdValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetAllFurnitureVariantsByModelIdValidator.cs index de3f3f9..aac20d3 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/GetAllFurnitureVariantsByModelIdValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetAllFurnitureVariantsByModelIdValidator.cs @@ -1,7 +1,7 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant { public class GetAllFurnitureVariantsByModelIdValidator : AbstractValidator { diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/GetFurnitureVariantByIdValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetFurnitureVariantByIdValidator.cs similarity index 74% rename from Core.Inventory.Application/UseCases/Inventory/Validator/GetFurnitureVariantByIdValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetFurnitureVariantByIdValidator.cs index 66e5c63..7879af3 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/GetFurnitureVariantByIdValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetFurnitureVariantByIdValidator.cs @@ -1,13 +1,13 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant { public class GetFurnitureVariantByIdValidator : AbstractValidator { public GetFurnitureVariantByIdValidator() { - RuleFor(x => x.Id) + RuleFor(x => x.MongoId) .NotEmpty().WithMessage("Id is required."); } } diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetFurnitureVariantsByIdsValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetFurnitureVariantsByIdsValidator.cs new file mode 100644 index 0000000..52a7e61 --- /dev/null +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/GetFurnitureVariantsByIdsValidator.cs @@ -0,0 +1,27 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant +{ + /// + /// Validator for . + /// + public class GetFurnitureVariantsByIdsValidator : AbstractValidator + { + public GetFurnitureVariantsByIdsValidator() + { + RuleFor(x => x.Ids) + .NotNull() + .WithMessage("The list of IDs must not be null.") + .Must(ids => ids.Length!=0) + .WithMessage("At least one ID must be provided.") + .Must(ids => ids.All(id => !string.IsNullOrWhiteSpace(id))) + .WithMessage("All IDs must be non-empty strings."); + } + } +} diff --git a/Core.Inventory.Application/UseCases/Inventory/Validator/UpdateFurnitureVariantValidator.cs b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/UpdateFurnitureVariantValidator.cs similarity index 93% rename from Core.Inventory.Application/UseCases/Inventory/Validator/UpdateFurnitureVariantValidator.cs rename to Core.Inventory.Application/UseCases/Inventory/Validator/Variant/UpdateFurnitureVariantValidator.cs index 6fc1183..473b533 100644 --- a/Core.Inventory.Application/UseCases/Inventory/Validator/UpdateFurnitureVariantValidator.cs +++ b/Core.Inventory.Application/UseCases/Inventory/Validator/Variant/UpdateFurnitureVariantValidator.cs @@ -1,7 +1,7 @@ -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using FluentValidation; -namespace Core.Inventory.Application.UseCases.Inventory.Validator +namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant { public class UpdateFurnitureVariantValidator : AbstractValidator { diff --git a/Core.Inventory.External/Clients/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/IInventoryServiceClient.cs index f8eef21..4a6f83c 100644 --- a/Core.Inventory.External/Clients/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/IInventoryServiceClient.cs @@ -13,8 +13,8 @@ namespace Core.Inventory.External.Clients [Get("/api/v1/FurnitureBase")] Task> GetAllFurnitureBaseAsync(CancellationToken cancellationToken = default); - [Get("/api/v1/FurnitureBase/{id}")] - Task GetFurnitureBaseByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + [Get("/api/v1/FurnitureBase/{mongoId}")] + Task GetFurnitureBaseByIdAsync([FromRoute] string mongoId, CancellationToken cancellationToken = default); [Post("/api/v1/FurnitureBase")] Task CreateFurnitureBaseAsync([FromBody] FurnitureBaseRequest request, CancellationToken cancellationToken = default); @@ -22,18 +22,21 @@ namespace Core.Inventory.External.Clients [Put("/api/v1/FurnitureBase/{id}")] Task UpdateFurnitureBaseAsync([FromBody] FurnitureBaseRequest request, [FromRoute] string id, CancellationToken cancellationToken = default); - [Patch("/api/v1/FurnitureBase/{id}/{newStatus}/ChangeStatus")] - Task ChangeFurnitureBaseStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); + [Patch("/api/v1/FurnitureBase/{mongoId}/{newStatus}/ChangeStatus")] + Task ChangeFurnitureBaseStatusAsync([FromRoute] string mongoId, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); #endregion #region FurnitureVariant - [Get("/api/v1/FurnitureVariant/{modelId}")] + [Get("/api/v1/FurnitureVariant/ByModel/{modelId}")] Task> GetAllVariantsByModelIdAsync([FromRoute] string modelId, CancellationToken cancellationToken = default); - [Get("/api/v1/FurnitureVariant/{id}/byId")] - Task GetFurnitureVariantByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + [Get("/api/v1/FurnitureVariant/{mongoId}")] + Task GetFurnitureVariantByIdAsync([FromRoute] string mongoId, CancellationToken cancellationToken = default); + + [Post("/api/v1/FurnitureVariant/ByIds")] + Task> GetFurnitureVariantsByIdsAsync([Body] string[] ids, CancellationToken cancellationToken = default); [Post("/api/v1/FurnitureVariant")] Task CreateFurnitureVariantAsync([FromBody] FurnitureVariantRequest request, CancellationToken cancellationToken = default); @@ -41,8 +44,8 @@ namespace Core.Inventory.External.Clients [Put("/api/v1/FurnitureVariant/{id}")] Task UpdateFurnitureVariantAsync([FromBody] FurnitureVariantRequest request, [FromRoute] string id, CancellationToken cancellationToken = default); - [Patch("/api/v1/FurnitureVariant/{id}/{newStatus}/ChangeStatus")] - Task ChangeFurnitureVariantStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); + [Patch("/api/v1/FurnitureVariant/{mongoId}/{newStatus}/ChangeStatus")] + Task ChangeFurnitureVariantStatusAsync([FromRoute] string mongoId, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); #endregion } diff --git a/Core.Inventory.Service.API/Controllers/FurnitureBaseController.cs b/Core.Inventory.Service.API/Controllers/FurnitureBaseController.cs index e3de54c..67ba3b1 100644 --- a/Core.Inventory.Service.API/Controllers/FurnitureBaseController.cs +++ b/Core.Inventory.Service.API/Controllers/FurnitureBaseController.cs @@ -1,5 +1,5 @@ using Asp.Versioning; -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; using Core.Inventory.Application.UseCases.Inventory.Ports; using Lib.Architecture.BuildingBlocks; using Microsoft.AspNetCore.Mvc; @@ -10,30 +10,20 @@ namespace Core.Inventory.Service.API.Controllers [Route("api/v{api-version:apiVersion}/[controller]")] [Produces("application/json")] [ApiController] - public class FurnitureBaseController : ControllerBase + public class FurnitureBaseController( + IComponentHandler getByIdHandler, + IComponentHandler getAllHandler, + IComponentHandler createHandler, + IComponentHandler updateHandler, + IComponentHandler changeStatusHandler, + IFurnitureBasePort port) : 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; - } + private readonly IComponentHandler _getByIdHandler = getByIdHandler; + private readonly IComponentHandler _getAllHandler = getAllHandler; + private readonly IComponentHandler _createHandler = createHandler; + private readonly IComponentHandler _updateHandler = updateHandler; + private readonly IComponentHandler _changeStatusHandler = changeStatusHandler; + private readonly IFurnitureBasePort _port = port; [HttpGet("GetAll")] public async Task GetAllAsync(CancellationToken cancellationToken) @@ -45,7 +35,7 @@ namespace Core.Inventory.Service.API.Controllers [HttpPost("GetById")] public async Task GetByIdAsync([FromBody] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture base identifier is required"); + if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture base identifier is required"); await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; @@ -68,7 +58,7 @@ namespace Core.Inventory.Service.API.Controllers [HttpPatch("ChangeStatus")] public async Task ChangeStatusAsync([FromBody] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture base identifier is required"); + if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture base identifier is required"); await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; diff --git a/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs b/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs index 7e6bb78..458df20 100644 --- a/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs +++ b/Core.Inventory.Service.API/Controllers/FurnitureVariantController.cs @@ -1,5 +1,5 @@ using Asp.Versioning; -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using Core.Inventory.Application.UseCases.Inventory.Ports; using Lib.Architecture.BuildingBlocks; using Microsoft.AspNetCore.Mvc; @@ -16,6 +16,7 @@ namespace Core.Inventory.Service.API.Controllers IComponentHandler createHandler, IComponentHandler updateHandler, IComponentHandler changeStatusHandler, + IComponentHandler getByIdsHandler, IFurnitureVariantPort port) : ControllerBase { private readonly IComponentHandler _getByIdHandler = getByIdHandler; @@ -23,6 +24,7 @@ namespace Core.Inventory.Service.API.Controllers private readonly IComponentHandler _createHandler = createHandler; private readonly IComponentHandler _updateHandler = updateHandler; private readonly IComponentHandler _changeStatusHandler = changeStatusHandler; + private readonly IComponentHandler _getByIdsHandler = getByIdsHandler; private readonly IFurnitureVariantPort _port = port; [HttpGet("GetAllByModelId")] @@ -38,12 +40,23 @@ namespace Core.Inventory.Service.API.Controllers [HttpPost("GetById")] public async Task GetByIdAsync([FromBody] GetFurnitureVariantByIdRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture variant identifier is required"); + if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture variant identifier is required"); await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); return _port.ViewModel; } + [HttpPost("GetByIds")] + public async Task GetByIdsAsync([FromBody] GetFurnitureVariantsByIdsRequest request, CancellationToken cancellationToken) + { + if (request?.Ids is null || request.Ids.Length == 0) + return BadRequest("At least one furniture variant ID must be provided."); + + await _getByIdsHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + return _port.ViewModel; + } + + [HttpPost("Create")] public async Task CreateAsync([FromBody] CreateFurnitureVariantRequest request, CancellationToken cancellationToken) { @@ -61,7 +74,7 @@ namespace Core.Inventory.Service.API.Controllers [HttpPatch("ChangeStatus")] public async Task ChangeStatusAsync([FromBody] ChangeFurnitureVariantStatusRequest request, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture variant identifier is required"); + if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture variant identifier is required"); await _changeStatusHandler.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 6d88d54..1dca9dd 100644 --- a/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs +++ b/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs @@ -1,8 +1,10 @@ using Core.Inventory.Application.UseCases.Inventory; using Core.Inventory.Application.UseCases.Inventory.Adapter; -using Core.Inventory.Application.UseCases.Inventory.Input; +using Core.Inventory.Application.UseCases.Inventory.Input.Base; +using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using Core.Inventory.Application.UseCases.Inventory.Ports; -using Core.Inventory.Application.UseCases.Inventory.Validator; +using Core.Inventory.Application.UseCases.Inventory.Validator.Base; +using Core.Inventory.Application.UseCases.Inventory.Validator.Variant; using FluentValidation; using Lib.Architecture.BuildingBlocks; @@ -42,6 +44,7 @@ namespace Core.Inventory.Service.API.Extensions services.AddScoped, InventoryHandler>(); services.AddScoped, InventoryHandler>(); services.AddScoped, InventoryHandler>(); + services.AddScoped, InventoryHandler>(); services.AddValidatorsFromAssemblyContaining(); services.AddScoped, CreateFurnitureVariantValidator>(); @@ -57,6 +60,9 @@ namespace Core.Inventory.Service.API.Extensions services.AddValidatorsFromAssemblyContaining(); services.AddScoped, GetAllFurnitureVariantsByModelIdValidator>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, GetFurnitureVariantsByIdsValidator>(); #endregion return services;