First version of Service
This commit is contained in:
		| @@ -0,0 +1,33 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="FurnitureBasePort.cs"> | ||||
| //     Core.Inventory.Application | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Adapter | ||||
| { | ||||
|     public class FurnitureBasePort : BasePresenter, IFurnitureBasePort | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Handles success with a single <see cref="FurnitureBase"/>. | ||||
|         /// </summary> | ||||
|         /// <param name="output">The output adapter.</param> | ||||
|         public void Success(FurnitureBase output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles success with a list of <see cref="FurnitureBase"/>. | ||||
|         /// </summary> | ||||
|         /// <param name="output">The output list.</param> | ||||
|         public void Success(List<FurnitureBase> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,37 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="FurnitureVariantPort.cs"> | ||||
| //     Core.Inventory.Application | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Adapter | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Presenter for FurnitureVariant use cases. Maps output to HTTP responses. | ||||
|     /// </summary> | ||||
|     public class FurnitureVariantPort : BasePresenter, IFurnitureVariantPort | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Handles success with a single <see cref="FurnitureVariant"/>. | ||||
|         /// </summary> | ||||
|         /// <param name="output">The output adapter.</param> | ||||
|         public void Success(FurnitureVariant output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles success with a list of <see cref="FurnitureVariant"/>. | ||||
|         /// </summary> | ||||
|         /// <param name="output">The output list.</param> | ||||
|         public void Success(List<FurnitureVariant> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,25 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="ChangeFurnitureBaseStatusRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Command to change the status of a furniture base model. | ||||
|     /// </summary> | ||||
|     public class ChangeFurnitureBaseStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(Id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,24 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="ChangeFurnitureVariantStatusRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Command to change the status of a furniture variant. | ||||
|     /// </summary> | ||||
|     public class ChangeFurnitureVariantStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(Id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,18 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="Dimensions.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input.Common | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Value object representing the dimensions of a furniture item. | ||||
|     /// </summary> | ||||
|     public class Dimensions | ||||
|     { | ||||
|         public float Width { get; set; } | ||||
|         public float Height { get; set; } | ||||
|         public float Depth { get; set; } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,33 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="CreateFurnitureBaseRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input.Common; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Command for creating a new furniture base entity. | ||||
|     /// </summary> | ||||
|     public class CreateFurnitureBaseRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string ModelName { get; set; } = null!; | ||||
|         public string Material { get; set; } = null!; | ||||
|         public string Condition { get; set; } = null!; | ||||
|         public string? BaseDescription { get; set; } | ||||
|         public string? Representation { get; set; } | ||||
|         public string? MaintenanceNotes { get; set; } | ||||
|  | ||||
|         public Dimensions Dimensions { get; set; } = new(); | ||||
|  | ||||
|         public List<string>? VariantIds { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(ModelName) && | ||||
|                    !string.IsNullOrWhiteSpace(Material) && | ||||
|                    !string.IsNullOrWhiteSpace(Condition); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,37 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="CreateFurnitureVariantRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     public class CreateFurnitureVariantRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string ModelId { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string Color { get; set; } = null!; | ||||
|         public string? Line { get; set; } | ||||
|  | ||||
|         public decimal Price { get; set; } | ||||
|         public string Currency { get; set; } = "USD"; | ||||
|         public int Stock { get; set; } | ||||
|  | ||||
|         public Guid CategoryId { get; set; } | ||||
|         public Guid ProviderId { get; set; } | ||||
|  | ||||
|         public Dictionary<string, object> Attributes { get; set; } = []; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(ModelId) | ||||
|                 && !string.IsNullOrWhiteSpace(Name) | ||||
|                 && !string.IsNullOrWhiteSpace(Color) | ||||
|                 && Price >= 0 | ||||
|                 && Stock >= 0 | ||||
|                 && CategoryId != Guid.Empty | ||||
|                 && ProviderId != Guid.Empty; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="GetAllFurnitureBaseRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     public class GetAllFurnitureBaseRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() => true; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="GetAllFurnitureVariantsByModelIdRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     public class GetAllFurnitureVariantsByModelIdRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string ModelId { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(ModelId); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="GetFurnitureBaseByIdRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Query to retrieve a furniture base by its identifier. | ||||
|     /// </summary> | ||||
|     public class GetFurnitureBaseByIdRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(Id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="GetFurnitureVariantByIdRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     public class GetFurnitureVariantByIdRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(Id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="UpdateFurnitureBaseRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input.Common; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Command for updating an existing furniture base entity. | ||||
|     /// </summary> | ||||
|     public class UpdateFurnitureBaseRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string ModelName { get; set; } = null!; | ||||
|         public string Material { get; set; } = null!; | ||||
|         public string Condition { get; set; } = null!; | ||||
|         public string? BaseDescription { get; set; } | ||||
|         public string? Representation { get; set; } | ||||
|         public string? MaintenanceNotes { get; set; } | ||||
|  | ||||
|         public Dimensions Dimensions { get; set; } = new(); | ||||
|  | ||||
|         public List<string>? VariantIds { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(Id) | ||||
|                 && !string.IsNullOrWhiteSpace(ModelName) | ||||
|                 && !string.IsNullOrWhiteSpace(Material) | ||||
|                 && !string.IsNullOrWhiteSpace(Condition); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,41 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="UpdateFurnitureVariantRequest.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Command for updating an existing furniture variant. | ||||
|     /// </summary> | ||||
|     public class UpdateFurnitureVariantRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string ModelId { get; set; } = null!; | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string Color { get; set; } = null!; | ||||
|         public string? Line { get; set; } | ||||
|  | ||||
|         public int Stock { get; set; } | ||||
|         public decimal Price { get; set; } | ||||
|         public string Currency { get; set; } = "USD"; | ||||
|  | ||||
|         public Guid CategoryId { get; set; } | ||||
|         public Guid ProviderId { get; set; } | ||||
|  | ||||
|         public Dictionary<string, object> Attributes { get; set; } = []; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(Id) && | ||||
|                    !string.IsNullOrWhiteSpace(ModelId) && | ||||
|                    !string.IsNullOrWhiteSpace(Name) && | ||||
|                    !string.IsNullOrWhiteSpace(Color) && | ||||
|                    Price > 0 && | ||||
|                    Stock >= 0; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,324 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||
| using Core.Inventory.External.Clients; | ||||
| using Core.Inventory.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory | ||||
| { | ||||
|     public class InventoryHandler : | ||||
|         // FurnitureBase | ||||
|         IComponentHandler<CreateFurnitureBaseRequest>, | ||||
|         IComponentHandler<UpdateFurnitureBaseRequest>, | ||||
|         IComponentHandler<GetAllFurnitureBaseRequest>, | ||||
|         IComponentHandler<ChangeFurnitureBaseStatusRequest>, | ||||
|         IComponentHandler<GetFurnitureBaseByIdRequest>, | ||||
|         // FurnitureVariant | ||||
|         IComponentHandler<CreateFurnitureVariantRequest>, | ||||
|         IComponentHandler<UpdateFurnitureVariantRequest>, | ||||
|         IComponentHandler<GetFurnitureVariantByIdRequest>, | ||||
|         IComponentHandler<GetAllFurnitureVariantsByModelIdRequest>, | ||||
|         IComponentHandler<ChangeFurnitureVariantStatusRequest> | ||||
|     { | ||||
|         // FurnitureBase | ||||
|         private readonly IFurnitureBasePort _basePort; | ||||
|         private readonly IValidator<CreateFurnitureBaseRequest> _createBaseValidator; | ||||
|         private readonly IValidator<UpdateFurnitureBaseRequest> _updateBaseValidator; | ||||
|         private readonly IValidator<ChangeFurnitureBaseStatusRequest> _changeBaseStatusValidator; | ||||
|  | ||||
|         // FurnitureVariant | ||||
|         private readonly IFurnitureVariantPort _variantPort; | ||||
|         private readonly IValidator<CreateFurnitureVariantRequest> _createVariantValidator; | ||||
|         private readonly IValidator<UpdateFurnitureVariantRequest> _updateVariantValidator; | ||||
|         private readonly IValidator<ChangeFurnitureVariantStatusRequest> _changeVariantStatusValidator; | ||||
|  | ||||
|         private readonly IInventoryServiceClient _inventoryDALService; | ||||
|  | ||||
|         public InventoryHandler( | ||||
|         // FurnitureBase | ||||
|             IFurnitureBasePort basePort, | ||||
|             IValidator<CreateFurnitureBaseRequest> createBaseValidator, | ||||
|             IValidator<UpdateFurnitureBaseRequest> updateBaseValidator, | ||||
|             IValidator<ChangeFurnitureBaseStatusRequest> changeBaseStatusValidator, | ||||
|  | ||||
|         // FurnitureVariant | ||||
|             IFurnitureVariantPort variantPort, | ||||
|             IValidator<CreateFurnitureVariantRequest> createVariantValidator, | ||||
|             IValidator<UpdateFurnitureVariantRequest> updateVariantValidator, | ||||
|             IValidator<ChangeFurnitureVariantStatusRequest> changeVariantStatusValidator, | ||||
|  | ||||
|             IInventoryServiceClient inventoryDALService | ||||
|             ) | ||||
|         { | ||||
|             _basePort= basePort; | ||||
|             _createBaseValidator= createBaseValidator; | ||||
|             _updateBaseValidator= updateBaseValidator; | ||||
|             _changeBaseStatusValidator= changeBaseStatusValidator; | ||||
|             _variantPort= variantPort; | ||||
|             _createVariantValidator= createVariantValidator; | ||||
|             _updateVariantValidator= updateVariantValidator; | ||||
|             _changeVariantStatusValidator= changeVariantStatusValidator; | ||||
|             _inventoryDALService= inventoryDALService; | ||||
|         } | ||||
|  | ||||
|         #region FurnitureBase | ||||
|         public async ValueTask ExecuteAsync(CreateFurnitureBaseRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 if (!command.IsValid(_createBaseValidator)) | ||||
|                 { | ||||
|                     _basePort.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new FurnitureBaseRequest | ||||
|                 { | ||||
|                     BaseDescription = command.BaseDescription, | ||||
|                     Condition = command.Condition, | ||||
|                     MaintenanceNotes = command.MaintenanceNotes, | ||||
|                     Material = command.Material, | ||||
|                     ModelName = command.ModelName, | ||||
|                     Representation = command.Representation, | ||||
|                     VariantIds = command.VariantIds, | ||||
|                     Dimensions = new Adapters.Lib.Dimensions | ||||
|                     { | ||||
|                         Depth = command.Dimensions.Depth, | ||||
|                         Height = command.Dimensions.Height, | ||||
|                         Width = command.Dimensions.Width | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryDALService.CreateFurnitureBaseAsync(request, cancellationToken); | ||||
|                 _basePort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _basePort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateFurnitureBaseRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 if (!command.IsValid(_updateBaseValidator)) | ||||
|                 { | ||||
|                     _basePort.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new FurnitureBaseRequest | ||||
|                 { | ||||
|                     BaseDescription = command.BaseDescription, | ||||
|                     Condition = command.Condition, | ||||
|                     MaintenanceNotes = command.MaintenanceNotes, | ||||
|                     Material = command.Material, | ||||
|                     ModelName = command.ModelName, | ||||
|                     Representation = command.Representation, | ||||
|                     VariantIds = command.VariantIds, | ||||
|                     Dimensions = new Adapters.Lib.Dimensions | ||||
|                     { | ||||
|                         Depth = command.Dimensions.Depth, | ||||
|                         Height = command.Dimensions.Height, | ||||
|                         Width = command.Dimensions.Width | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryDALService.UpdateFurnitureBaseAsync(request, command.Id, cancellationToken); | ||||
|                 _basePort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _basePort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllFurnitureBaseRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await _inventoryDALService.GetAllFurnitureBaseAsync(cancellationToken); | ||||
|                 if (!result.Any()) | ||||
|                 { | ||||
|                     _basePort.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _basePort.Success([.. result]); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _basePort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetFurnitureBaseByIdRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.Id, cancellationToken); | ||||
|                 if (result is null) | ||||
|                 { | ||||
|                     _basePort.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _basePort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _basePort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeFurnitureBaseStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 if (!command.IsValid(_changeBaseStatusValidator)) | ||||
|                 { | ||||
|                     _basePort.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.Id, command.Status, cancellationToken); | ||||
|                 _basePort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _basePort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         #endregion | ||||
|  | ||||
|         #region FurnitureVariant | ||||
|         public async ValueTask ExecuteAsync(CreateFurnitureVariantRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 if (!command.IsValid(_createVariantValidator)) | ||||
|                 { | ||||
|                     _variantPort.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|                 var request = new FurnitureVariantRequest | ||||
|                 { | ||||
|                     Stock = command.Stock, | ||||
|                     Attributes= command.Attributes, | ||||
|                     CategoryId = command.CategoryId, | ||||
|                     Color = command.Color, | ||||
|                     Currency = command.Currency, | ||||
|                     Line = command.Line, | ||||
|                     ModelId = command.ModelId, | ||||
|                     Name = command.Name, | ||||
|                     Price = command.Price, | ||||
|                     ProviderId  = command.ProviderId | ||||
|                 }; | ||||
|                 var result = await _inventoryDALService.CreateFurnitureVariantAsync(request, cancellationToken); | ||||
|                 _variantPort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _variantPort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateFurnitureVariantRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 if (!command.IsValid(_updateVariantValidator)) | ||||
|                 { | ||||
|                     _variantPort.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|                 var request = new FurnitureVariantRequest | ||||
|                 { | ||||
|                     Stock = command.Stock, | ||||
|                     Attributes= command.Attributes, | ||||
|                     CategoryId = command.CategoryId, | ||||
|                     Color = command.Color, | ||||
|                     Currency = command.Currency, | ||||
|                     Line = command.Line, | ||||
|                     ModelId = command.ModelId, | ||||
|                     Name = command.Name, | ||||
|                     Price = command.Price, | ||||
|                     ProviderId = command.ProviderId | ||||
|                 }; | ||||
|                 var result = await _inventoryDALService.UpdateFurnitureVariantAsync(request, command.Id, cancellationToken); | ||||
|                 _variantPort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _variantPort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetFurnitureVariantByIdRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.Id, cancellationToken); | ||||
|                 if (result is null) | ||||
|                 { | ||||
|                     _variantPort.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _variantPort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _variantPort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllFurnitureVariantsByModelIdRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 var result = await _inventoryDALService.GetAllVariantsByModelIdAsync(command.ModelId, cancellationToken); | ||||
|                 if (!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 | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|                 if (!command.IsValid(_changeVariantStatusValidator)) | ||||
|                 { | ||||
|                     _variantPort.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|                 var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.Id, command.Status, cancellationToken); | ||||
|                 _variantPort.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _variantPort); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="IFurnitureBasePort.cs"> | ||||
| //     Core.Inventory.Application | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Adapters.Lib; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Ports | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Output port interface for handling results from FurnitureBase use cases. | ||||
|     /// </summary> | ||||
|     public interface IFurnitureBasePort : IBasePort, | ||||
|         ICommandSuccessPort<FurnitureBase>, | ||||
|         ICommandSuccessPort<List<FurnitureBase>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="IFurnitureVariantPort.cs"> | ||||
| //     Core.Inventory.Application | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Adapters.Lib; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Ports | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Output port interface for handling results from FurnitureVariant use cases. | ||||
|     /// </summary> | ||||
|     public interface IFurnitureVariantPort : IBasePort, | ||||
|         ICommandSuccessPort<FurnitureVariant>, | ||||
|         ICommandSuccessPort<List<FurnitureVariant>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class ChangeFurnitureBaseStatusValidator : AbstractValidator<ChangeFurnitureBaseStatusRequest> | ||||
|     { | ||||
|         public ChangeFurnitureBaseStatusValidator() | ||||
|         { | ||||
|             RuleFor(x => x.Id) | ||||
|                 .NotEmpty().WithMessage("Id is required."); | ||||
|  | ||||
|             RuleFor(x => x.Status) | ||||
|                 .IsInEnum().WithMessage("Invalid status value."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class ChangeFurnitureVariantStatusValidator : AbstractValidator<ChangeFurnitureVariantStatusRequest> | ||||
|     { | ||||
|         public ChangeFurnitureVariantStatusValidator() | ||||
|         { | ||||
|             RuleFor(x => x.Id) | ||||
|                 .NotEmpty().WithMessage("Id is required."); | ||||
|  | ||||
|             RuleFor(x => x.Status) | ||||
|                 .IsInEnum().WithMessage("Invalid status value."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input.Common; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator.Common | ||||
| { | ||||
|     public class DimensionsValidator : AbstractValidator<Dimensions> | ||||
|     { | ||||
|         public DimensionsValidator() | ||||
|         { | ||||
|             RuleFor(x => x.Width) | ||||
|                 .GreaterThan(0).WithMessage("Width must be greater than 0."); | ||||
|  | ||||
|             RuleFor(x => x.Height) | ||||
|                 .GreaterThan(0).WithMessage("Height must be greater than 0."); | ||||
|  | ||||
|             RuleFor(x => x.Depth) | ||||
|                 .GreaterThan(0).WithMessage("Depth must be greater than 0."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,29 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="CreateFurnitureBaseValidator.cs"> | ||||
| //     Core.Inventory | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Common; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class CreateFurnitureBaseValidator : AbstractValidator<CreateFurnitureBaseRequest> | ||||
|     { | ||||
|         public CreateFurnitureBaseValidator() | ||||
|         { | ||||
|             RuleFor(x => x.ModelName) | ||||
|                .NotEmpty().WithMessage("Model name is required."); | ||||
|  | ||||
|             RuleFor(x => x.Material) | ||||
|                 .NotEmpty().WithMessage("Material is required."); | ||||
|  | ||||
|             RuleFor(x => x.Condition) | ||||
|                 .NotEmpty().WithMessage("Condition is required."); | ||||
|  | ||||
|             RuleFor(x => x.Dimensions) | ||||
|                .SetValidator(new DimensionsValidator()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class CreateFurnitureVariantValidator : AbstractValidator<CreateFurnitureVariantRequest> | ||||
|     { | ||||
|         public CreateFurnitureVariantValidator() | ||||
|         { | ||||
|             RuleFor(x => x.ModelId) | ||||
|                 .NotEmpty().WithMessage("ModelId is required."); | ||||
|  | ||||
|             RuleFor(x => x.Name) | ||||
|                 .NotEmpty().WithMessage("Name is required."); | ||||
|  | ||||
|             RuleFor(x => x.Color) | ||||
|                 .NotEmpty().WithMessage("Color is required."); | ||||
|  | ||||
|             RuleFor(x => x.Price) | ||||
|                 .GreaterThanOrEqualTo(0).WithMessage("Price must be a non-negative value."); | ||||
|  | ||||
|             RuleFor(x => x.Stock) | ||||
|                 .GreaterThanOrEqualTo(0).WithMessage("Stock must be a non-negative value."); | ||||
|  | ||||
|             RuleFor(x => x.CategoryId) | ||||
|                 .NotEqual(Guid.Empty).WithMessage("CategoryId is required."); | ||||
|  | ||||
|             RuleFor(x => x.ProviderId) | ||||
|                 .NotEqual(Guid.Empty).WithMessage("ProviderId is required."); | ||||
|  | ||||
|             RuleFor(x => x.Currency) | ||||
|                 .NotEmpty().WithMessage("Currency is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class GetAllFurnitureVariantsByModelIdValidator : AbstractValidator<GetAllFurnitureVariantsByModelIdRequest> | ||||
|     { | ||||
|         public GetAllFurnitureVariantsByModelIdValidator() | ||||
|         { | ||||
|             RuleFor(x => x.ModelId) | ||||
|                 .NotEmpty().WithMessage("ModelId is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class GetFurnitureBaseByIdValidator : AbstractValidator<GetFurnitureBaseByIdRequest> | ||||
|     { | ||||
|         public GetFurnitureBaseByIdValidator() | ||||
|         { | ||||
|             RuleFor(x => x.Id) | ||||
|                 .NotEmpty().WithMessage("Id is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class GetFurnitureVariantByIdValidator : AbstractValidator<GetFurnitureVariantByIdRequest> | ||||
|     { | ||||
|         public GetFurnitureVariantByIdValidator() | ||||
|         { | ||||
|             RuleFor(x => x.Id) | ||||
|                 .NotEmpty().WithMessage("Id is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,24 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Common; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class UpdateFurnitureBaseValidator : AbstractValidator<UpdateFurnitureBaseRequest> | ||||
|     { | ||||
|         public UpdateFurnitureBaseValidator() | ||||
|         { | ||||
|             RuleFor(x => x.ModelName) | ||||
|                .NotEmpty().WithMessage("Model name is required."); | ||||
|  | ||||
|             RuleFor(x => x.Material) | ||||
|                 .NotEmpty().WithMessage("Material is required."); | ||||
|  | ||||
|             RuleFor(x => x.Condition) | ||||
|                 .NotEmpty().WithMessage("Condition is required."); | ||||
|  | ||||
|             RuleFor(x => x.Dimensions) | ||||
|                .SetValidator(new DimensionsValidator()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,38 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | ||||
| { | ||||
|     public class UpdateFurnitureVariantValidator : AbstractValidator<UpdateFurnitureVariantRequest> | ||||
|     { | ||||
|         public UpdateFurnitureVariantValidator() | ||||
|         { | ||||
|             RuleFor(x => x.Id) | ||||
|                 .NotEmpty().WithMessage("Id is required."); | ||||
|  | ||||
|             RuleFor(x => x.ModelId) | ||||
|                 .NotEmpty().WithMessage("ModelId is required."); | ||||
|  | ||||
|             RuleFor(x => x.Name) | ||||
|                 .NotEmpty().WithMessage("Name is required."); | ||||
|  | ||||
|             RuleFor(x => x.Color) | ||||
|                 .NotEmpty().WithMessage("Color is required."); | ||||
|  | ||||
|             RuleFor(x => x.Price) | ||||
|                 .GreaterThan(0).WithMessage("Price must be greater than 0."); | ||||
|  | ||||
|             RuleFor(x => x.Stock) | ||||
|                 .GreaterThanOrEqualTo(0).WithMessage("Stock must be a non-negative value."); | ||||
|  | ||||
|             RuleFor(x => x.Currency) | ||||
|                 .NotEmpty().WithMessage("Currency is required."); | ||||
|  | ||||
|             RuleFor(x => x.CategoryId) | ||||
|                 .NotEqual(Guid.Empty).WithMessage("CategoryId is required."); | ||||
|  | ||||
|             RuleFor(x => x.ProviderId) | ||||
|                 .NotEqual(Guid.Empty).WithMessage("ProviderId is required."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user