From bed3202892b03eaac14bc415247261dc27a618f3 Mon Sep 17 00:00:00 2001 From: Efrain Marin Date: Wed, 6 Aug 2025 18:11:19 -0600 Subject: [PATCH] feat: added endpoint DeleteProduct - feat: Added Product controller and endpoints - feat: package updated --- .../Controllers/ProductController.cs | 47 +++++++++++++++++++ .../Inventory/IInventoryServiceClient.cs | 3 ++ .../Requests/Product/CreateProductRequest.cs | 2 +- .../Requests/Product/DeleteProductRequest.cs | 14 ++++++ .../Requests/Product/UpdateProductRequest.cs | 2 +- .../Core.Inventory.External.csproj | 2 +- 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/Product/DeleteProductRequest.cs diff --git a/Core.Inventory.BFF.API/Controllers/ProductController.cs b/Core.Inventory.BFF.API/Controllers/ProductController.cs index 693b19d..b8556e6 100644 --- a/Core.Inventory.BFF.API/Controllers/ProductController.cs +++ b/Core.Inventory.BFF.API/Controllers/ProductController.cs @@ -171,6 +171,15 @@ namespace Core.Inventory.BFF.API.Controllers /// /// Changes the status of the Product. /// + /// The request containing the product ID and new ProductStatus. + /// The updated entity. + /// The Product updates. + /// The Product not found. + /// The Product could not be updated. + /// The Product could not be updated. + /// The Product could not be updated. + /// The Product could not be updated. + /// The service internal error. [HttpPatch] [Route("ChangeStatus")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -256,5 +265,43 @@ namespace Core.Inventory.BFF.API.Controllers throw; } } + + /// + /// Deletes a Product by its identifier. + /// + /// The request containing the product ID to delete. + /// Cancellation token for the asynchronous operation. + /// The representing the result of the service call. + /// The Product deleted successfully. + /// No content if the Product was not found. + /// Bad request if the Product ID is missing or invalid. + /// Unauthorized if the user is not authenticated. + /// Precondition failed if the request does not meet expected conditions. + /// Unprocessable entity if the request cannot be processed. + /// Internal server error if an unexpected error occurs. + [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 DeleteProductService([FromBody] DeleteProductRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(DeleteProductService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); + + if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid Product identifier"); } + + return await Handle(() => inventoryServiceClient.DeleteProductService(request, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(DeleteProductService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); + throw; + } + } } } \ No newline at end of file diff --git a/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs index 77fa443..9fce721 100644 --- a/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs @@ -131,6 +131,9 @@ namespace Core.Inventory.External.Clients.Inventory [Delete("/api/v1/Product/RemoveTag")] Task> RemoveTagFromProductAsync([Header("TrackingId")][Body] RemoveTagFromProductRequest request, CancellationToken cancellationToken = default); + [Delete("/api/v1/Product/Delete")] + Task> DeleteProductService([Header("TrackingId")][Body] DeleteProductRequest request, CancellationToken cancellationToken = default); + #endregion } } diff --git a/Core.Inventory.External/Clients/Inventory/Requests/Product/CreateProductRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/Product/CreateProductRequest.cs index 8869847..7a1fd48 100644 --- a/Core.Inventory.External/Clients/Inventory/Requests/Product/CreateProductRequest.cs +++ b/Core.Inventory.External/Clients/Inventory/Requests/Product/CreateProductRequest.cs @@ -5,7 +5,7 @@ namespace Core.Inventory.External.Clients.Inventory.Requests.Product 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 TagIds { get; set; } = new List(); } } \ No newline at end of file diff --git a/Core.Inventory.External/Clients/Inventory/Requests/Product/DeleteProductRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/Product/DeleteProductRequest.cs new file mode 100644 index 0000000..f7dfbe7 --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/Product/DeleteProductRequest.cs @@ -0,0 +1,14 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.External.Clients.Inventory.Requests.Product +{ + public class DeleteProductRequest : Notificator, ICommand + { + public string Id { get; set; } = null!; + + public bool Validate() + { + return Id != null; + } + } +} \ No newline at end of file diff --git a/Core.Inventory.External/Clients/Inventory/Requests/Product/UpdateProductRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/Product/UpdateProductRequest.cs index c0dfd40..94818b6 100644 --- a/Core.Inventory.External/Clients/Inventory/Requests/Product/UpdateProductRequest.cs +++ b/Core.Inventory.External/Clients/Inventory/Requests/Product/UpdateProductRequest.cs @@ -8,7 +8,7 @@ namespace Core.Inventory.External.Clients.Inventory.Requests.Product 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 TagIds { get; set; } = new List(); } } \ No newline at end of file diff --git a/Core.Inventory.External/Core.Inventory.External.csproj b/Core.Inventory.External/Core.Inventory.External.csproj index 011ea64..2c5fc6b 100644 --- a/Core.Inventory.External/Core.Inventory.External.csproj +++ b/Core.Inventory.External/Core.Inventory.External.csproj @@ -7,7 +7,7 @@ - +