Compare commits
	
		
			12 Commits
		
	
	
		
			fc093e8bff
			...
			developmen
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 8f64fd51c0 | ||
| a858e5e5de | |||
| c1df5e354b | |||
|   | 27d1bb680b | ||
| 4fa4693bb9 | |||
| 6d044e5de7 | |||
| 34ada90a28 | |||
| b529d905b1 | |||
|   | 85e186396d | ||
| a63a351b84 | |||
| ab3863943d | |||
| c446fa652e | 
							
								
								
									
										12
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| **/bin | ||||
| **/obj | ||||
| **/out | ||||
| **/.vs | ||||
| **/.idea | ||||
| **/.git | ||||
| **/.gitignore | ||||
| **/node_modules | ||||
| *.user | ||||
| *.swp | ||||
| *.swo | ||||
| .DS_Store | ||||
| @@ -19,10 +19,10 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||
|         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 string Icon { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(ModelName) && | ||||
|   | ||||
| @@ -21,10 +21,10 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||
|         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 string Icon { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return !string.IsNullOrWhiteSpace(_Id) | ||||
|   | ||||
| @@ -13,15 +13,13 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||
|         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 string CategoryId { get; set; } = string.Empty; | ||||
|         public string ProviderId { get; set; } = string.Empty; | ||||
|  | ||||
|         public Dictionary<string, string> Attributes { get; set; } = []; | ||||
|         public string Icon { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|   | ||||
| @@ -23,11 +23,10 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||
|         public int Stock { get; set; } | ||||
|         public decimal Price { get; set; } | ||||
|         public string Currency { get; set; } = "USD"; | ||||
|  | ||||
|         public string CategoryId { get; set; } = string.Empty!; | ||||
|         public string ProviderId { get; set; } = string.Empty!; | ||||
|  | ||||
|         public Dictionary<string, string> Attributes { get; set; } = []; | ||||
|         public string Icon { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|   | ||||
| @@ -94,7 +94,8 @@ namespace Core.Inventory.Application.UseCases.Inventory | ||||
|                         Depth = command.Dimensions.Depth, | ||||
|                         Height = command.Dimensions.Height, | ||||
|                         Width = command.Dimensions.Width | ||||
|                     } | ||||
|                     }, | ||||
|                     Icon = command.Icon | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryDALService.CreateFurnitureBaseAsync(request, cancellationToken); | ||||
| @@ -133,7 +134,8 @@ namespace Core.Inventory.Application.UseCases.Inventory | ||||
|                         Depth = command.Dimensions.Depth, | ||||
|                         Height = command.Dimensions.Height, | ||||
|                         Width = command.Dimensions.Width | ||||
|                     } | ||||
|                     }, | ||||
|                     Icon = command.Icon | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryDALService.UpdateFurnitureBaseAsync(command.Id, request, cancellationToken); | ||||
| @@ -226,7 +228,8 @@ namespace Core.Inventory.Application.UseCases.Inventory | ||||
|                     ModelId = command.ModelId, | ||||
|                     Name = command.Name, | ||||
|                     Price = command.Price, | ||||
|                     ProviderId  = command.ProviderId | ||||
|                     ProviderId  = command.ProviderId, | ||||
|                     Icon = command.Icon | ||||
|                 }; | ||||
|                 var result = await _inventoryDALService.CreateFurnitureVariantAsync(request, cancellationToken); | ||||
|                 _variantPort.Success(result); | ||||
| @@ -260,7 +263,8 @@ namespace Core.Inventory.Application.UseCases.Inventory | ||||
|                     ModelId = command.ModelId, | ||||
|                     Name = command.Name, | ||||
|                     Price = command.Price, | ||||
|                     ProviderId = command.ProviderId | ||||
|                     ProviderId = command.ProviderId, | ||||
|                     Icon = command.Icon | ||||
|                 }; | ||||
|                 var result = await _inventoryDALService.UpdateFurnitureVariantAsync(command.Id, request, cancellationToken); | ||||
|                 _variantPort.Success(result); | ||||
|   | ||||
| @@ -0,0 +1,7 @@ | ||||
| namespace Core.Inventory.Application.UseCases.Product.Adapter | ||||
| { | ||||
|     public class DeleteProductResponseAdapter | ||||
|     { | ||||
|         public bool Success { get; init; } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,23 @@ | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Core.Inventory.Application.UseCases.Product.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Adapter | ||||
| { | ||||
|     public class ProductPort : BasePresenter, IProductPort | ||||
|     { | ||||
|         public void Success(ProductAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<ProductAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(DeleteProductResponseAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class ChangeProductStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public ProductStatus NewStatus { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,18 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class CreateProductRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string ProductName { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|         public string ProductStatus { get; set; } = null!; | ||||
|         public List<string> TagIds { get; set; } = new List<string>(); | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return ProductName != null; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class DeleteProductRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class GetAllProductsByListRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string[] Products { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Products != null && Products.Any(); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class GetAllProductsRequest : Notificator, ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class GetProductRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,20 @@ | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Input | ||||
| { | ||||
|     public class UpdateProductRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string ProductName { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|         public string ProductStatus { get; set; } = null!; | ||||
|         public List<string> TagIds { get; set; } = new List<string>(); | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null && ProductName != null; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Core.Inventory.Application.UseCases.Product.Adapter; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Ports | ||||
| { | ||||
|     public interface IProductPort : IBasePort, | ||||
|         ICommandSuccessPort<ProductAdapter>, | ||||
|         ICommandSuccessPort<List<ProductAdapter>>, | ||||
|         ICommandSuccessPort<DeleteProductResponseAdapter>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| }  | ||||
							
								
								
									
										247
									
								
								Core.Inventory.Application/UseCases/Product/ProductHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										247
									
								
								Core.Inventory.Application/UseCases/Product/ProductHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,247 @@ | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Core.Inventory.Application.UseCases.Product.Adapter; | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using Core.Inventory.Application.UseCases.Product.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.Product | ||||
| { | ||||
|     public class ProductHandler : | ||||
|         IComponentHandler<ChangeProductStatusRequest>, | ||||
|         IComponentHandler<GetAllProductsRequest>, | ||||
|         IComponentHandler<GetAllProductsByListRequest>, | ||||
|         IComponentHandler<UpdateProductRequest>, | ||||
|         IComponentHandler<GetProductRequest>, | ||||
|         IComponentHandler<CreateProductRequest>, | ||||
|         IComponentHandler<DeleteProductRequest> | ||||
|     { | ||||
|         private readonly IProductPort _port; | ||||
|         private readonly IValidator<ChangeProductStatusRequest> _changeProductStatusValidator; | ||||
|         private readonly IValidator<CreateProductRequest> _registerProductValidator; | ||||
|         private readonly IValidator<UpdateProductRequest> _updateProductValidator; | ||||
|         private readonly IValidator<GetAllProductsByListRequest> _productsByListValidator; | ||||
|         private readonly IValidator<DeleteProductRequest> _deleteProductValidator; | ||||
|         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||
|  | ||||
|         public ProductHandler( | ||||
|             IProductPort port, | ||||
|             IValidator<ChangeProductStatusRequest> changeProductStatusValidator, | ||||
|             IValidator<CreateProductRequest> registerProductValidator, | ||||
|             IValidator<UpdateProductRequest> updateProductValidator, | ||||
|             IValidator<GetAllProductsByListRequest> productsByListValidator, | ||||
|             IValidator<DeleteProductRequest> deleteProductValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeProductStatusValidator = changeProductStatusValidator ?? throw new ArgumentNullException(nameof(changeProductStatusValidator)); | ||||
|             _registerProductValidator = registerProductValidator ?? throw new ArgumentNullException(nameof(registerProductValidator)); | ||||
|             _updateProductValidator = updateProductValidator ?? throw new ArgumentNullException(nameof(updateProductValidator)); | ||||
|             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||
|             _productsByListValidator = productsByListValidator ?? throw new ArgumentNullException(nameof(productsByListValidator)); | ||||
|             _deleteProductValidator = deleteProductValidator ?? throw new ArgumentNullException(nameof(deleteProductValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetProductRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.GetProductByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllProductsRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllProductsAsync(cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllProductsByListRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_productsByListValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllProductsByListAsync(command.Products, cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeProductStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeProductStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.ChangeProductStatusAsync(command.Id, command.NewStatus, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateProductRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerProductValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var productRequest = new ProductRequest | ||||
|                 { | ||||
|                     TenantId = command.TenantId, | ||||
|                     ProductName = command.ProductName, | ||||
|                     Description = command.Description, | ||||
|                     ProductStatus = command.ProductStatus, | ||||
|                     TagIds = command.TagIds | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.CreateProductAsync(productRequest, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateProductRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateProductValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var productAdapter = new ProductAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     TenantId = command.TenantId, | ||||
|                     ProductName = command.ProductName, | ||||
|                     Description = command.Description, | ||||
|                     ProductStatus = Enum.Parse<ProductStatus>(command.ProductStatus), | ||||
|                     TagIds = command.TagIds.Select(id => MongoDB.Bson.ObjectId.Parse(id)).ToList() | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.UpdateProductAsync(productAdapter, command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(DeleteProductRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_deleteProductValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.DeleteProductAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (!result) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(new DeleteProductResponseAdapter() { Success = true }); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Validator | ||||
| { | ||||
|     public class ChangeProductStatusValidator : AbstractValidator<ChangeProductStatusRequest> | ||||
|     { | ||||
|         public ChangeProductStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Product Id").WithMessage("Product Id is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Validator | ||||
| { | ||||
|     public class CreateProductValidator : AbstractValidator<CreateProductRequest> | ||||
|     { | ||||
|         public CreateProductValidator() | ||||
|         { | ||||
|             RuleFor(i => i.ProductName).NotEmpty().NotNull().OverridePropertyName(x => x.ProductName).WithName("Product Name").WithMessage("Product Name is Obligatory."); | ||||
|             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Product Description").WithMessage("Product Description is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Validator | ||||
| { | ||||
|     public class DeleteProductValidator : AbstractValidator<DeleteProductRequest> | ||||
|     { | ||||
|         public DeleteProductValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Product Id").WithMessage("Product Id is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Validator | ||||
| { | ||||
|     public class GetAllProductsByListValidator : AbstractValidator<GetAllProductsByListRequest> | ||||
|     { | ||||
|         public GetAllProductsByListValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Products).NotEmpty().NotNull().OverridePropertyName(x => x.Products).WithName("Products").WithMessage("Products are Obligatory."); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Validator | ||||
| { | ||||
|     public class UpdateProductValidator : AbstractValidator<UpdateProductRequest> | ||||
|     { | ||||
|         public UpdateProductValidator() | ||||
|         { | ||||
|             RuleFor(i => i.ProductName).NotEmpty().NotNull().OverridePropertyName(x => x.ProductName).WithName("Product Name").WithMessage("Product Name is Obligatory."); | ||||
|             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Product Description").WithMessage("Product Description is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class DeleteTagRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -17,7 +17,8 @@ namespace Core.Inventory.Application.UseCases.Tag | ||||
|         IComponentHandler<GetTagRequest>, | ||||
|         IComponentHandler<CreateTagRequest>, | ||||
|         IComponentHandler<AddParentTagToTagRequest>, | ||||
|         IComponentHandler<RemoveParentTagFromTagRequest> | ||||
|         IComponentHandler<RemoveParentTagFromTagRequest>, | ||||
|         IComponentHandler<DeleteTagRequest> | ||||
|     { | ||||
|         private readonly ITagPort _port; | ||||
|         private readonly IValidator<ChangeTagStatusRequest> _changeTagStatusValidator; | ||||
| @@ -25,6 +26,7 @@ namespace Core.Inventory.Application.UseCases.Tag | ||||
|         private readonly IValidator<UpdateTagRequest> _updateTagValidator; | ||||
|         private readonly IValidator<GetAllTagsByListRequest> _TagsByListValidator; | ||||
|         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||
|         private readonly IValidator<DeleteTagRequest> _deleteTagValidator; | ||||
|  | ||||
|         public TagHandler( | ||||
|             ITagPort port, | ||||
| @@ -32,6 +34,7 @@ namespace Core.Inventory.Application.UseCases.Tag | ||||
|             IValidator<CreateTagRequest> registerTagValidator, | ||||
|             IValidator<UpdateTagRequest> updateTagValidator, | ||||
|             IValidator<GetAllTagsByListRequest> TagsByListValidator, | ||||
|             IValidator<DeleteTagRequest> deleteTagValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
| @@ -40,6 +43,7 @@ namespace Core.Inventory.Application.UseCases.Tag | ||||
|             _updateTagValidator = updateTagValidator ?? throw new ArgumentNullException(nameof(updateTagValidator)); | ||||
|             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||
|             _TagsByListValidator = TagsByListValidator ?? throw new ArgumentNullException(nameof(TagsByListValidator)); | ||||
|             _deleteTagValidator = deleteTagValidator ?? throw new ArgumentNullException(nameof(deleteTagValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTagRequest command, CancellationToken cancellationToken = default) | ||||
| @@ -262,5 +266,33 @@ namespace Core.Inventory.Application.UseCases.Tag | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(DeleteTagRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_deleteTagValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.DeleteTagAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Validator | ||||
| { | ||||
|     public class DeleteTagValidator : AbstractValidator<DeleteTagRequest> | ||||
|     { | ||||
|         public DeleteTagValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Tag Id").WithMessage("Tag Id is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Adapter | ||||
| { | ||||
|     public class TagOverridePort : BasePresenter, ITagOverridePort | ||||
|     { | ||||
|         public void Success(TagOverrideAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<TagOverrideAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class ChangeTagOverrideStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class CreateTagOverrideRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string BaseTagId { get; set; } = null!; | ||||
|         public string OverrideTagId { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return BaseTagId != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class DeleteTagOverrideRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class GetAllTagOverridesByListRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string[] TagOverrides { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return TagOverrides != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class GetAllTagOverridesRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class GetTagOverrideRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||
| { | ||||
|     public class UpdateTagOverrideRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string BaseTagId { get; set; } = null!; | ||||
|         public string OverrideTagId { get; set; } = null!; | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Ports | ||||
| { | ||||
|     public interface ITagOverridePort : IBasePort, | ||||
|         ICommandSuccessPort<TagOverrideAdapter>, | ||||
|         ICommandSuccessPort<List<TagOverrideAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,244 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.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.TagOverride | ||||
| { | ||||
|     public class TagOverrideHandler : | ||||
|         IComponentHandler<ChangeTagOverrideStatusRequest>, | ||||
|         IComponentHandler<GetAllTagOverridesRequest>, | ||||
|         IComponentHandler<GetAllTagOverridesByListRequest>, | ||||
|         IComponentHandler<UpdateTagOverrideRequest>, | ||||
|         IComponentHandler<GetTagOverrideRequest>, | ||||
|         IComponentHandler<CreateTagOverrideRequest>, | ||||
|         IComponentHandler<DeleteTagOverrideRequest> | ||||
|     { | ||||
|         private readonly ITagOverridePort _port; | ||||
|         private readonly IValidator<ChangeTagOverrideStatusRequest> _changeTagOverrideStatusValidator; | ||||
|         private readonly IValidator<CreateTagOverrideRequest> _registerTagOverrideValidator; | ||||
|         private readonly IValidator<UpdateTagOverrideRequest> _updateTagOverrideValidator; | ||||
|         private readonly IValidator<GetAllTagOverridesByListRequest> _TagOverridesByListValidator; | ||||
|         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||
|         private readonly IValidator<DeleteTagOverrideRequest> _deleteTagOverrideValidator; | ||||
|  | ||||
|         public TagOverrideHandler( | ||||
|             ITagOverridePort port, | ||||
|             IValidator<ChangeTagOverrideStatusRequest> changeTagOverrideStatusValidator, | ||||
|             IValidator<CreateTagOverrideRequest> registerTagOverrideValidator, | ||||
|             IValidator<UpdateTagOverrideRequest> updateTagOverrideValidator, | ||||
|             IValidator<GetAllTagOverridesByListRequest> TagOverridesByListValidator, | ||||
|             IValidator<DeleteTagOverrideRequest> deleteTagOverrideValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeTagOverrideStatusValidator = changeTagOverrideStatusValidator ?? throw new ArgumentNullException(nameof(changeTagOverrideStatusValidator)); | ||||
|             _registerTagOverrideValidator = registerTagOverrideValidator ?? throw new ArgumentNullException(nameof(registerTagOverrideValidator)); | ||||
|             _updateTagOverrideValidator = updateTagOverrideValidator ?? throw new ArgumentNullException(nameof(updateTagOverrideValidator)); | ||||
|             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||
|             _TagOverridesByListValidator = TagOverridesByListValidator ?? throw new ArgumentNullException(nameof(TagOverridesByListValidator)); | ||||
|             _deleteTagOverrideValidator = deleteTagOverrideValidator ?? throw new ArgumentNullException(nameof(deleteTagOverrideValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.GetTagOverrideByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllTagOverridesRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllTagOverridesAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllTagOverridesByListRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_TagOverridesByListValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllTagOverridesByListAsync(command.TagOverrides, cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeTagOverrideStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeTagOverrideStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.ChangeStatusTagOverrideAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerTagOverrideValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new TagOverrideRequest | ||||
|                 { | ||||
|                     TenantId = command.TenantId, | ||||
|                     BaseTagId = command.BaseTagId, | ||||
|                     OverrideTagId = command.OverrideTagId, | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.CreateTagOverrideAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateTagOverrideValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new TagOverrideAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     TenantId = command.TenantId, | ||||
|                     BaseTagId = command.BaseTagId, | ||||
|                     OverrideTagId = command.OverrideTagId | ||||
|                 }; | ||||
|  | ||||
|                 string id = command.Id; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.UpdateTagOverrideAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(DeleteTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_deleteTagOverrideValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.DeleteTagOverrideAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||
| { | ||||
|     public class ChangeTagOverrideStatusValidator : AbstractValidator<ChangeTagOverrideStatusRequest> | ||||
|     { | ||||
|         public ChangeTagOverrideStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagOverride ID").WithMessage("TagOverride ID is Obligatory."); | ||||
|             RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||
| { | ||||
|     public class CreateTagOverrideValidator : AbstractValidator<CreateTagOverrideRequest> | ||||
|     { | ||||
|         public CreateTagOverrideValidator() | ||||
|         { | ||||
|             RuleFor(i => i.BaseTagId).NotEmpty().NotNull().OverridePropertyName(x => x.BaseTagId).WithName("TagOverride BaseTagId").WithMessage("TagOverride BaseTagId is Obligatory."); | ||||
|             RuleFor(i => i.OverrideTagId).NotEmpty().NotNull().OverridePropertyName(x => x.OverrideTagId).WithName("TagOverride OverrideTagId").WithMessage("TagOverride OverrideTagId is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||
| { | ||||
|     public class DeleteTagOverrideValidator : AbstractValidator<DeleteTagOverrideRequest> | ||||
|     { | ||||
|         public DeleteTagOverrideValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagOverride Id").WithMessage("TagOverride Id is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||
| { | ||||
|     public class GetAllTagOverridesByListValidator : AbstractValidator<GetAllTagOverridesByListRequest> | ||||
|     { | ||||
|         public GetAllTagOverridesByListValidator() | ||||
|         { | ||||
|             RuleFor(i => i.TagOverrides).NotEmpty().NotNull().OverridePropertyName(x => x.TagOverrides).WithName("TagOverrides").WithMessage("TagOverrides are Obligatory."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||
| { | ||||
|     public class UpdateTagOverrideValidator : AbstractValidator<UpdateTagOverrideRequest> | ||||
|     { | ||||
|         public UpdateTagOverrideValidator() | ||||
|         { | ||||
|             RuleFor(i => i.BaseTagId).NotEmpty().NotNull().OverridePropertyName(x => x.BaseTagId).WithName("TagOverride BaseTagId").WithMessage("TagOverride BaseTagId is Obligatory."); | ||||
|             RuleFor(i => i.OverrideTagId).NotEmpty().NotNull().OverridePropertyName(x => x.OverrideTagId).WithName("TagOverride OverrideTagId").WithMessage("TagOverride OverrideTagId is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Input | ||||
| { | ||||
|     public class DeleteTagTypeRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,9 +1,4 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Input | ||||
| { | ||||
|   | ||||
| @@ -15,13 +15,15 @@ namespace Core.Inventory.Application.UseCases.TagType | ||||
|         IComponentHandler<GetAllTagTypesByListRequest>, | ||||
|         IComponentHandler<UpdateTagTypeRequest>, | ||||
|         IComponentHandler<GetTagTypeRequest>, | ||||
|         IComponentHandler<CreateTagTypeRequest> | ||||
|         IComponentHandler<CreateTagTypeRequest>, | ||||
|         IComponentHandler<DeleteTagTypeRequest> | ||||
|     { | ||||
|         private readonly ITagTypePort _port; | ||||
|         private readonly IValidator<ChangeTagTypeStatusRequest> _changeTagTypeStatusValidator; | ||||
|         private readonly IValidator<CreateTagTypeRequest> _registerTagTypeValidator; | ||||
|         private readonly IValidator<UpdateTagTypeRequest> _updateTagTypeValidator; | ||||
|         private readonly IValidator<GetAllTagTypesByListRequest> _TagTypesByListValidator; | ||||
|         private readonly IValidator<DeleteTagTypeRequest> _deleteTagTypeValidator; | ||||
|         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||
|  | ||||
|         public TagTypeHandler( | ||||
| @@ -30,6 +32,7 @@ namespace Core.Inventory.Application.UseCases.TagType | ||||
|             IValidator<CreateTagTypeRequest> registerTagTypeValidator, | ||||
|             IValidator<UpdateTagTypeRequest> updateTagTypeValidator, | ||||
|             IValidator<GetAllTagTypesByListRequest> TagTypesByListValidator, | ||||
|             IValidator<DeleteTagTypeRequest> deleteTagTypeValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
| @@ -38,6 +41,7 @@ namespace Core.Inventory.Application.UseCases.TagType | ||||
|             _updateTagTypeValidator = updateTagTypeValidator ?? throw new ArgumentNullException(nameof(updateTagTypeValidator)); | ||||
|             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||
|             _TagTypesByListValidator = TagTypesByListValidator ?? throw new ArgumentNullException(nameof(TagTypesByListValidator)); | ||||
|             _deleteTagTypeValidator = deleteTagTypeValidator ?? throw new ArgumentNullException(nameof(deleteTagTypeValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTagTypeRequest command, CancellationToken cancellationToken = default) | ||||
| @@ -210,5 +214,33 @@ namespace Core.Inventory.Application.UseCases.TagType | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(DeleteTagTypeRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_deleteTagTypeValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.DeleteTagTypeAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Validator | ||||
| { | ||||
|     public class DeleteTagTypeValidator : AbstractValidator<DeleteTagTypeRequest> | ||||
|     { | ||||
|         public DeleteTagTypeValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagType Id").WithMessage("TagType Id is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -15,5 +15,6 @@ namespace Core.Inventory.External.Clients.Adapters | ||||
|  | ||||
|         public Dimensions Dimensions { get; set; } = new(); | ||||
|         public List<string>? VariantIds { get; set; } | ||||
|         public string Icon { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -17,5 +17,6 @@ | ||||
|         public string ProviderId { get; set; } = string.Empty!; | ||||
|  | ||||
|         public Dictionary<string, string> Attributes { get; set; } = []; | ||||
|         public string Icon { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Inventory.External.Clients.Adapters; | ||||
| using Core.Inventory.External.Clients.Requests; | ||||
| @@ -72,6 +73,9 @@ namespace Core.Inventory.External.Clients | ||||
|         [Patch("/api/v1/TagType/{id}/{newStatus}/ChangeStatus")] | ||||
|         Task<TagTypeAdapter> ChangeStatusTagTypeAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/api/v1/TagType/{id}")] | ||||
|         Task<TagTypeAdapter> DeleteTagTypeAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|  | ||||
|         #region Tag | ||||
| @@ -100,6 +104,65 @@ namespace Core.Inventory.External.Clients | ||||
|         [Delete("/api/v1/Tag/{tagId}/ParentTags/{parentTagId}/Remove")] | ||||
|         Task<TagAdapter> RemoveParentTagAsync([FromRoute] string tagId, [FromRoute] string parentTagId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/api/v1/Tag/{id}")] | ||||
|         Task<TagAdapter> DeleteTagAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|  | ||||
|         #region TagOverride | ||||
|  | ||||
|         [Get("/api/v1/TagOverride")] | ||||
|         Task<IEnumerable<TagOverrideAdapter>> GetAllTagOverridesAsync(CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/TagOverride/GetTagOverrideList")] | ||||
|         Task<IEnumerable<TagOverrideAdapter>> GetAllTagOverridesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Get("/api/v1/TagOverride/{id}")] | ||||
|         Task<TagOverrideAdapter> GetTagOverrideByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/TagOverride")] | ||||
|         Task<TagOverrideAdapter> CreateTagOverrideAsync([FromBody] TagOverrideRequest newTagOverride, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Put("/api/v1/TagOverride/{id}")] | ||||
|         Task<TagOverrideAdapter> UpdateTagOverrideAsync([FromBody] TagOverrideAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Patch("/api/v1/TagOverride/{id}/{newStatus}/ChangeStatus")] | ||||
|         Task<TagOverrideAdapter> ChangeStatusTagOverrideAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/api/v1/TagOverride/{id}")] | ||||
|         Task<TagOverrideAdapter> DeleteTagOverrideAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|  | ||||
|         #region Product | ||||
|  | ||||
|         [Get("/api/v1/Product")] | ||||
|         Task<IEnumerable<ProductAdapter>> GetAllProductsAsync(CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/Product/GetProductList")] | ||||
|         Task<IEnumerable<ProductAdapter>> GetAllProductsByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Get("/api/v1/Product/{id}")] | ||||
|         Task<ProductAdapter> GetProductByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/Product")] | ||||
|         Task<ProductAdapter> CreateProductAsync([FromBody] ProductRequest newProduct, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Put("/api/v1/Product/{id}")] | ||||
|         Task<ProductAdapter> UpdateProductAsync([FromBody] ProductAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Patch("/api/v1/Product/{id}/{newStatus}/ChangeStatus")] | ||||
|         Task<ProductAdapter> ChangeProductStatusAsync([FromRoute] string id, [FromRoute] ProductStatus newStatus, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/Product/{productId}/tags/{tagId}")] | ||||
|         Task<ProductAdapter> AddTagToProductAsync([FromRoute] string productId, [FromRoute] string tagId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/api/v1/Product/{productId}/tags/{tagId}")] | ||||
|         Task<ProductAdapter> RemoveTagFromProductAsync([FromRoute] string productId, [FromRoute] string tagId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/api/v1/Product/{id}")] | ||||
|         Task<bool> DeleteProductAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -10,8 +10,8 @@ namespace Core.Inventory.External.Clients.Requests | ||||
|         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 string Icon { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -15,5 +15,7 @@ | ||||
|         public string ProviderId { get; set; } = string.Empty!; | ||||
|  | ||||
|         public Dictionary<string, string> Attributes { get; set; } = []; | ||||
|  | ||||
|         public string Icon { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										11
									
								
								Core.Inventory.External/Clients/Requests/ProductRequest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Core.Inventory.External/Clients/Requests/ProductRequest.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| namespace Core.Inventory.External.Clients.Requests | ||||
| { | ||||
|     public class ProductRequest | ||||
|     { | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string ProductName { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|         public string ProductStatus { get; set; } = null!; | ||||
|         public List<string> TagIds { get; set; } = new List<string>(); | ||||
|     } | ||||
| }  | ||||
| @@ -0,0 +1,9 @@ | ||||
| namespace Core.Inventory.External.Clients.Requests | ||||
| { | ||||
|     public class TagOverrideRequest | ||||
|     { | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string BaseTagId { get; set; } = null!; | ||||
|         public string OverrideTagId { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
| @@ -7,8 +7,8 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Adapters.Lib" Version="1.0.10" /> | ||||
|     <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> | ||||
|     <PackageReference Include="Core.Adapters.Lib" Version="1.0.1" /> | ||||
|     <PackageReference Include="Lib.Architecture.BuildingBlocks" Version="1.0.0" /> | ||||
|     <PackageReference Include="Refit" Version="8.0.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   | ||||
							
								
								
									
										232
									
								
								Core.Inventory.Service.API/Controllers/ProductController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								Core.Inventory.Service.API/Controllers/ProductController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,232 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using Core.Inventory.Application.UseCases.Product.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="ProductController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [AllowAnonymous] | ||||
|     public class ProductController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetProductRequest> getProductHandler; | ||||
|         private readonly IComponentHandler<GetAllProductsRequest> getAllProductsHandler; | ||||
|         private readonly IComponentHandler<GetAllProductsByListRequest> getAllProductsByListHandler; | ||||
|         private readonly IComponentHandler<CreateProductRequest> createProductHandler; | ||||
|         private readonly IComponentHandler<UpdateProductRequest> updateProductHandler; | ||||
|         private readonly IComponentHandler<ChangeProductStatusRequest> changeProductStatusHandler; | ||||
|         private readonly IComponentHandler<DeleteProductRequest> deleteProductHandler; | ||||
|         private readonly IProductPort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="ProductController"/>. | ||||
|         /// </summary> | ||||
|         public ProductController( | ||||
|             IComponentHandler<GetProductRequest> getProductHandler, | ||||
|             IComponentHandler<GetAllProductsRequest> getAllProductsHandler, | ||||
|             IComponentHandler<GetAllProductsByListRequest> getAllProductsByListHandler, | ||||
|             IComponentHandler<CreateProductRequest> createProductHandler, | ||||
|             IComponentHandler<UpdateProductRequest> updateProductHandler, | ||||
|             IComponentHandler<ChangeProductStatusRequest> changeProductStatusHandler, | ||||
|             IComponentHandler<DeleteProductRequest> deleteProductHandler, | ||||
|             IProductPort port | ||||
|             ) | ||||
|         { | ||||
|             this.createProductHandler = createProductHandler; | ||||
|             this.updateProductHandler = updateProductHandler; | ||||
|             this.changeProductStatusHandler = changeProductStatusHandler; | ||||
|             this.getAllProductsHandler = getAllProductsHandler; | ||||
|             this.getProductHandler = getProductHandler; | ||||
|             this.getAllProductsByListHandler = getAllProductsByListHandler; | ||||
|             this.deleteProductHandler = deleteProductHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the Products. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> GetAllProductsAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllProductsHandler.ExecuteAsync(new GetAllProductsRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the Products by Product identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of Product identifiers.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The Products found.</response> | ||||
|         /// <response code="204">No content if no Products are found.</response> | ||||
|         /// <response code="400">Bad request if the Product identifiers are missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost] | ||||
|         [Route("GetProductList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<ProductAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> GetAllProductsByListAsync([FromBody] GetAllProductsByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request == null || request.Products == null || !request.Products.Any()) | ||||
|             { | ||||
|                 return BadRequest("Product identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             await getAllProductsByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the Product by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> GetProductById([FromBody] GetProductRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request.Id == null || !request.Id.Any()) | ||||
|             { | ||||
|                 return BadRequest("Invalid Product Id"); | ||||
|             } | ||||
|  | ||||
|             await getProductHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new Product. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> CreateProductAsync([FromBody] CreateProductRequest newProduct, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createProductHandler.ExecuteAsync(newProduct, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full Product by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> UpdateProductAsync([FromBody] UpdateProductRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateProductHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the Product. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the product ID and new ProductStatus.</param> | ||||
|         /// <returns>The <see cref="ProductAdapter"/> updated entity.</returns> | ||||
|         /// <response code="200">The Product updates.</response> | ||||
|         /// <response code="204">The Product not found.</response> | ||||
|         /// <response code="400">The Product could not be updated.</response> | ||||
|         /// <response code="401">The Product could not be updated.</response> | ||||
|         /// <response code="412">The Product could not be updated.</response> | ||||
|         /// <response code="422">The Product could not be updated.</response> | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> ChangeProductStatusAsync([FromBody] ChangeProductStatusRequest request, | ||||
|                                                                      CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid Product identifier"); } | ||||
|  | ||||
|             await changeProductStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Product by its MongoDB identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the product ID to delete.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The Product deleted successfully.</response> | ||||
|         /// <response code="204">No content if the Product was not found.</response> | ||||
|         /// <response code="400">Bad request if the Product ID is missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpDelete("Delete")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> DeleteProductAsync([FromBody] DeleteProductRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) | ||||
|             { | ||||
|                 return BadRequest("Invalid Product identifier"); | ||||
|             } | ||||
|  | ||||
|             await deleteProductHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -2,6 +2,7 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using Core.Inventory.Application.UseCases.Tag.Ports; | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| @@ -26,6 +27,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         private readonly IComponentHandler<ChangeTagStatusRequest> changeTagStatusHandler; | ||||
|         private readonly IComponentHandler<AddParentTagToTagRequest> addParentTagToTagHandler; | ||||
|         private readonly IComponentHandler<RemoveParentTagFromTagRequest> removeParentTagFromTagUserHandler; | ||||
|         private readonly IComponentHandler<DeleteTagRequest> deleteTagHandler; | ||||
|         private readonly ITagPort port; | ||||
|  | ||||
|         /// <summary> | ||||
| @@ -40,6 +42,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|             IComponentHandler<ChangeTagStatusRequest> changeTagStatusHandler, | ||||
|             IComponentHandler<AddParentTagToTagRequest> addParentTagToTagHandler, | ||||
|             IComponentHandler<RemoveParentTagFromTagRequest> removeParentTagFromTagUserHandler, | ||||
|             IComponentHandler<DeleteTagRequest> deleteTagHandler, | ||||
|             ITagPort port | ||||
|             ) | ||||
|         { | ||||
| @@ -51,6 +54,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|             this.getAllTagsByListHandler = getAllTagsByListHandler; | ||||
|             this.addParentTagToTagHandler = addParentTagToTagHandler; | ||||
|             this.removeParentTagFromTagUserHandler = removeParentTagFromTagUserHandler; | ||||
|             this.deleteTagHandler = deleteTagHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
| @@ -235,5 +239,23 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a full Tag by identifier. | ||||
|         /// </summary> | ||||
|         [HttpDelete("Delete")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> UpdateTagAsync([FromBody] DeleteTagRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await deleteTagHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										208
									
								
								Core.Inventory.Service.API/Controllers/TagOverrideController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								Core.Inventory.Service.API/Controllers/TagOverrideController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,208 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="TagOverrideController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [AllowAnonymous] | ||||
|     public class TagOverrideController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetTagOverrideRequest> getTagOverrideHandler; | ||||
|         private readonly IComponentHandler<GetAllTagOverridesRequest> getAllTagOverridesHandler; | ||||
|         private readonly IComponentHandler<GetAllTagOverridesByListRequest> getAllTagOverridesByListHandler; | ||||
|         private readonly IComponentHandler<CreateTagOverrideRequest> createTagOverrideHandler; | ||||
|         private readonly IComponentHandler<UpdateTagOverrideRequest> updateTagOverrideHandler; | ||||
|         private readonly IComponentHandler<ChangeTagOverrideStatusRequest> changeTagOverrideStatusHandler; | ||||
|         private readonly IComponentHandler<DeleteTagOverrideRequest> deleteTagOverrideHandler; | ||||
|         private readonly ITagOverridePort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="TagOverrideController"/>. | ||||
|         /// </summary> | ||||
|         public TagOverrideController( | ||||
|             IComponentHandler<GetTagOverrideRequest> getTagOverrideHandler, | ||||
|             IComponentHandler<GetAllTagOverridesRequest> getAllTagOverridesHandler, | ||||
|             IComponentHandler<GetAllTagOverridesByListRequest> getAllTagOverridesByListHandler, | ||||
|             IComponentHandler<CreateTagOverrideRequest> createTagOverrideHandler, | ||||
|             IComponentHandler<UpdateTagOverrideRequest> updateTagOverrideHandler, | ||||
|             IComponentHandler<ChangeTagOverrideStatusRequest> changeTagOverrideStatusHandler, | ||||
|             IComponentHandler<DeleteTagOverrideRequest> deleteTagOverrideHandler, | ||||
|             ITagOverridePort port | ||||
|             ) | ||||
|         { | ||||
|             this.createTagOverrideHandler = createTagOverrideHandler; | ||||
|             this.updateTagOverrideHandler = updateTagOverrideHandler; | ||||
|             this.changeTagOverrideStatusHandler = changeTagOverrideStatusHandler; | ||||
|             this.getAllTagOverridesHandler = getAllTagOverridesHandler; | ||||
|             this.getTagOverrideHandler = getTagOverrideHandler; | ||||
|             this.getAllTagOverridesByListHandler = getAllTagOverridesByListHandler; | ||||
|             this.deleteTagOverrideHandler = deleteTagOverrideHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the TagOverrides. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> GetAllTagOverridesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllTagOverridesHandler.ExecuteAsync(new GetAllTagOverridesRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the TagOverrides by TagOverride identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of TagOverride identifiers.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The TagOverrides found.</response> | ||||
|         /// <response code="204">No content if no TagOverrides are found.</response> | ||||
|         /// <response code="400">Bad request if the TagOverride identifiers are missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost] | ||||
|         [Route("GetTagOverrideList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<TagOverrideAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> GetAllTagOverridesByListAsync([FromBody] GetAllTagOverridesByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request == null || request.TagOverrides == null || !request.TagOverrides.Any()) | ||||
|             { | ||||
|                 return BadRequest("TagOverride identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             await getAllTagOverridesByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the TagOverride by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> GetTagOverrideById([FromBody] GetTagOverrideRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request.Id == null || !request.Id.Any()) | ||||
|             { | ||||
|                 return BadRequest("Invalid TagOverride Id"); | ||||
|             } | ||||
|  | ||||
|             await getTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new TagOverride. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> CreateTagOverrideAsync([FromBody] CreateTagOverrideRequest newTagOverride, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createTagOverrideHandler.ExecuteAsync(newTagOverride, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full TagOverride by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> UpdateTagOverrideAsync([FromBody] UpdateTagOverrideRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the TagOverride. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> ChangeTagOverrideStatusAsync([FromBody] ChangeTagOverrideStatusRequest request, | ||||
|                                                                      CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagOverride identifier"); } | ||||
|  | ||||
|             await changeTagOverrideStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a full TagOverride by identifier. | ||||
|         /// </summary> | ||||
|         [HttpDelete("Delete")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> UpdateTagOverrideAsync([FromBody] DeleteTagOverrideRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await deleteTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -24,6 +24,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         private readonly IComponentHandler<CreateTagTypeRequest> createTagTypeHandler; | ||||
|         private readonly IComponentHandler<UpdateTagTypeRequest> updateTagTypeHandler; | ||||
|         private readonly IComponentHandler<ChangeTagTypeStatusRequest> changeTagTypeStatusHandler; | ||||
|         private readonly IComponentHandler<DeleteTagTypeRequest> deleteTagTypeHandler; | ||||
|         private readonly ITagTypePort port; | ||||
|  | ||||
|         /// <summary> | ||||
| @@ -36,6 +37,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|             IComponentHandler<CreateTagTypeRequest> createTagTypeHandler, | ||||
|             IComponentHandler<UpdateTagTypeRequest> updateTagTypeHandler, | ||||
|             IComponentHandler<ChangeTagTypeStatusRequest> changeTagTypeStatusHandler, | ||||
|             IComponentHandler<DeleteTagTypeRequest> deleteTagTypeHandler, | ||||
|             ITagTypePort port | ||||
|             ) | ||||
|         { | ||||
| @@ -45,6 +47,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|             this.getAllTagTypesHandler = getAllTagTypesHandler; | ||||
|             this.getTagTypeHandler = getTagTypeHandler; | ||||
|             this.getAllTagTypesByListHandler = getAllTagTypesByListHandler; | ||||
|             this.deleteTagTypeHandler = deleteTagTypeHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
| @@ -183,5 +186,23 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a full TagType by identifier. | ||||
|         /// </summary> | ||||
|         [HttpDelete("Delete")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> UpdateTagTypeAsync([FromBody] DeleteTagTypeRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await deleteTagTypeHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" /> | ||||
|     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" /> | ||||
|     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.0" /> | ||||
|     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   | ||||
| @@ -5,11 +5,21 @@ using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Base; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Variant; | ||||
| using Core.Inventory.Application.UseCases.Product; | ||||
| using Core.Inventory.Application.UseCases.Product.Adapter; | ||||
| using Core.Inventory.Application.UseCases.Product.Input; | ||||
| using Core.Inventory.Application.UseCases.Product.Ports; | ||||
| using Core.Inventory.Application.UseCases.Product.Validator; | ||||
| using Core.Inventory.Application.UseCases.Tag; | ||||
| using Core.Inventory.Application.UseCases.Tag.Adapter; | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using Core.Inventory.Application.UseCases.Tag.Ports; | ||||
| using Core.Inventory.Application.UseCases.Tag.Validator; | ||||
| using Core.Inventory.Application.UseCases.TagOverride; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Adapter; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Validator; | ||||
| using Core.Inventory.Application.UseCases.TagType; | ||||
| using Core.Inventory.Application.UseCases.TagType.Adapter; | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| @@ -98,6 +108,10 @@ namespace Core.Inventory.Service.API.Extensions | ||||
|             services.AddScoped<IValidator<ChangeTagTypeStatusRequest>, ChangeTagTypeStatusValidator>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeTagTypeStatusRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<DeleteTagTypeValidator>(); | ||||
|             services.AddScoped<IValidator<DeleteTagTypeRequest>, DeleteTagTypeValidator>(); | ||||
|             services.AddScoped<IComponentHandler<DeleteTagTypeRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             #region Tag Services | ||||
| @@ -125,6 +139,66 @@ namespace Core.Inventory.Service.API.Extensions | ||||
|             services.AddScoped<IComponentHandler<AddParentTagToTagRequest>, TagHandler>(); | ||||
|             services.AddScoped<IComponentHandler<RemoveParentTagFromTagRequest>, TagHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<DeleteTagValidator>(); | ||||
|             services.AddScoped<IValidator<DeleteTagRequest>, DeleteTagValidator>(); | ||||
|             services.AddScoped<IComponentHandler<DeleteTagRequest>, TagHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             #region TagOverride Services | ||||
|  | ||||
|             services.AddScoped<ITagOverridePort, TagOverridePort>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagOverridesRequest>, TagOverrideHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetAllTagOverridesByListValidator>(); | ||||
|             services.AddScoped<IValidator<GetAllTagOverridesByListRequest>, GetAllTagOverridesByListValidator>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagOverridesByListRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<CreateTagOverrideValidator>(); | ||||
|             services.AddScoped<IValidator<CreateTagOverrideRequest>, CreateTagOverrideValidator>(); | ||||
|             services.AddScoped<IComponentHandler<CreateTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<UpdateTagOverrideValidator>(); | ||||
|             services.AddScoped<IValidator<UpdateTagOverrideRequest>, UpdateTagOverrideValidator>(); | ||||
|             services.AddScoped<IComponentHandler<UpdateTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<ChangeTagOverrideStatusValidator>(); | ||||
|             services.AddScoped<IValidator<ChangeTagOverrideStatusRequest>, ChangeTagOverrideStatusValidator>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeTagOverrideStatusRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<DeleteTagOverrideValidator>(); | ||||
|             services.AddScoped<IValidator<DeleteTagOverrideRequest>, DeleteTagOverrideValidator>(); | ||||
|             services.AddScoped<IComponentHandler<DeleteTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             #region Product Services | ||||
|  | ||||
|             services.AddScoped<IProductPort, ProductPort>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllProductsRequest>, ProductHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetProductRequest>, ProductHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetAllProductsByListValidator>(); | ||||
|             services.AddScoped<IValidator<GetAllProductsByListRequest>, GetAllProductsByListValidator>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllProductsByListRequest>, ProductHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<CreateProductValidator>(); | ||||
|             services.AddScoped<IValidator<CreateProductRequest>, CreateProductValidator>(); | ||||
|             services.AddScoped<IComponentHandler<CreateProductRequest>, ProductHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<UpdateProductValidator>(); | ||||
|             services.AddScoped<IValidator<UpdateProductRequest>, UpdateProductValidator>(); | ||||
|             services.AddScoped<IComponentHandler<UpdateProductRequest>, ProductHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<ChangeProductStatusValidator>(); | ||||
|             services.AddScoped<IValidator<ChangeProductStatusRequest>, ChangeProductStatusValidator>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeProductStatusRequest>, ProductHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<DeleteProductValidator>(); | ||||
|             services.AddScoped<IValidator<DeleteProductRequest>, DeleteProductValidator>(); | ||||
|             services.AddScoped<IComponentHandler<DeleteProductRequest>, ProductHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             return services; | ||||
|   | ||||
							
								
								
									
										42
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| # ===== Build stage ===== | ||||
| FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||||
| WORKDIR /src | ||||
|  | ||||
| # Usaremos la config de NuGet de la raíz (BaGet + nuget.org) | ||||
| COPY nuget.config ./ | ||||
|  | ||||
| # Copiamos SOLO los .csproj primero (mejor caché en restore) | ||||
| COPY Core.Inventory.Service.API/Core.Inventory.Service.API.csproj Core.Inventory.Service.API/ | ||||
| COPY Core.Inventory.Application/Core.Inventory.Application.csproj Core.Inventory.Application/ | ||||
| COPY Core.Inventory.External/Core.Inventory.External.csproj Core.Inventory.External/ | ||||
|  | ||||
| # Restaura con tu nuget.config | ||||
| RUN dotnet restore Core.Inventory.Service.API/Core.Inventory.Service.API.csproj --configfile ./nuget.config | ||||
|  | ||||
| # Ahora sí, copia todo el código | ||||
| COPY . . | ||||
|  | ||||
| # Publica artefactos (sin apphost para imagen más pequeña) | ||||
| ARG BUILD_CONFIGURATION=Release | ||||
| RUN dotnet publish Core.Inventory.Service.API/Core.Inventory.Service.API.csproj \ | ||||
|     -c $BUILD_CONFIGURATION -o /app/out /p:UseAppHost=false | ||||
|  | ||||
| # ===== Runtime stage ===== | ||||
| FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime | ||||
| WORKDIR /app | ||||
|  | ||||
| # Copiamos el publish | ||||
| COPY --from=build /app/out . | ||||
|  | ||||
| # Variables típicas (ajústalas luego en compose) | ||||
| ENV ASPNETCORE_URLS=http://+:8080 \ | ||||
|     ASPNETCORE_ENVIRONMENT=Production | ||||
|  | ||||
| # Exponemos el puerto HTTP | ||||
| EXPOSE 8080 | ||||
|  | ||||
| # Opcional: healthcheck si tienes /health | ||||
| # HEALTHCHECK --interval=30s --timeout=5s --retries=5 \ | ||||
| #   CMD wget -qO- http://localhost:8080/health || exit 1 | ||||
|  | ||||
| ENTRYPOINT ["dotnet", "Core.Inventory.Service.API.dll"] | ||||
							
								
								
									
										9
									
								
								nuget.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								nuget.config
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <configuration> | ||||
|   <packageSources> | ||||
|     <!-- Tu BaGet primero --> | ||||
|     <add key="BaGet" value="https://nuget.dream-views.com/v3/index.json" protocolVersion="3" /> | ||||
|     <!-- NuGet oficial como fallback (si quieres) --> | ||||
|     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||||
|   </packageSources> | ||||
| </configuration> | ||||
		Reference in New Issue
	
	Block a user