feat: added endpoint DeleteProduct
- fix: adapters package updated - fix: status property renamed
This commit is contained in:
		| @@ -0,0 +1,7 @@ | ||||
| namespace Core.Inventory.Application.UseCases.Product.Adapter | ||||
| { | ||||
|     public class DeleteProductResponseAdapter | ||||
|     { | ||||
|         public bool Success { get; init; } | ||||
|     } | ||||
| }  | ||||
| @@ -15,5 +15,9 @@ namespace Core.Inventory.Application.UseCases.Product.Adapter | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(DeleteProductResponseAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -7,7 +7,7 @@ namespace Core.Inventory.Application.UseCases.Product.Input | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string ProductName { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|         public string Status { get; set; } = null!; | ||||
|         public string ProductStatus { get; set; } = null!; | ||||
|         public List<string> TagIds { get; set; } = new List<string>(); | ||||
|  | ||||
|         public bool Validate() | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| }  | ||||
| @@ -9,7 +9,7 @@ namespace Core.Inventory.Application.UseCases.Product.Input | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string ProductName { get; set; } = null!; | ||||
|         public string Description { get; set; } = null!; | ||||
|         public string Status { get; set; } = null!; | ||||
|         public string ProductStatus { get; set; } = null!; | ||||
|         public List<string> TagIds { get; set; } = new List<string>(); | ||||
|  | ||||
|         public bool Validate() | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Core.Adapters.Lib.Inventory; | ||||
| using Core.Inventory.Application.UseCases.Product.Adapter; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Product.Ports | ||||
| @@ -6,6 +7,7 @@ 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 | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| 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; | ||||
| @@ -15,13 +16,15 @@ namespace Core.Inventory.Application.UseCases.Product | ||||
|         IComponentHandler<GetAllProductsByListRequest>, | ||||
|         IComponentHandler<UpdateProductRequest>, | ||||
|         IComponentHandler<GetProductRequest>, | ||||
|         IComponentHandler<CreateProductRequest> | ||||
|         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( | ||||
| @@ -30,6 +33,7 @@ namespace Core.Inventory.Application.UseCases.Product | ||||
|             IValidator<CreateProductRequest> registerProductValidator, | ||||
|             IValidator<UpdateProductRequest> updateProductValidator, | ||||
|             IValidator<GetAllProductsByListRequest> productsByListValidator, | ||||
|             IValidator<DeleteProductRequest> deleteProductValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
| @@ -38,6 +42,7 @@ namespace Core.Inventory.Application.UseCases.Product | ||||
|             _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) | ||||
| @@ -153,7 +158,7 @@ namespace Core.Inventory.Application.UseCases.Product | ||||
|                     TenantId = command.TenantId, | ||||
|                     ProductName = command.ProductName, | ||||
|                     Description = command.Description, | ||||
|                     Status = command.Status, | ||||
|                     ProductStatus = command.ProductStatus, | ||||
|                     TagIds = command.TagIds | ||||
|                 }; | ||||
|  | ||||
| @@ -191,7 +196,7 @@ namespace Core.Inventory.Application.UseCases.Product | ||||
|                     TenantId = command.TenantId, | ||||
|                     ProductName = command.ProductName, | ||||
|                     Description = command.Description, | ||||
|                     Status = Enum.Parse<ProductStatus>(command.Status), | ||||
|                     ProductStatus = Enum.Parse<ProductStatus>(command.ProductStatus), | ||||
|                     TagIds = command.TagIds.Select(id => MongoDB.Bson.ObjectId.Parse(id)).ToList() | ||||
|                 }; | ||||
|  | ||||
| @@ -210,5 +215,33 @@ namespace Core.Inventory.Application.UseCases.Product | ||||
|                 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 DeleteProductValidator : AbstractValidator<DeleteProductRequest> | ||||
|     { | ||||
|         public DeleteProductValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Product Id").WithMessage("Product Id is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| }  | ||||
		Reference in New Issue
	
	Block a user