From d4d0a4d2d195a7b812a45a3721da890b10f80082 Mon Sep 17 00:00:00 2001 From: Oscar Morales Date: Fri, 8 Aug 2025 11:13:46 -0600 Subject: [PATCH] Add physical delete --- .../Controllers/TagController.cs | 30 +++++++++++++++++++ .../Controllers/TagOverrideController.cs | 28 +++++++++++++++++ .../Controllers/TagTypeController.cs | 27 +++++++++++++++++ .../Inventory/IInventoryServiceClient.cs | 9 ++++++ .../Requests/Tag/DeleteTagRequest.cs | 14 +++++++++ .../TagOverride/DeleteTagOverrideRequest.cs | 14 +++++++++ .../Requests/TagType/DeleteTagTypeRequest.cs | 14 +++++++++ 7 files changed, 136 insertions(+) create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/Tag/DeleteTagRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/DeleteTagOverrideRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagType/DeleteTagTypeRequest.cs diff --git a/Core.Inventory.BFF.API/Controllers/TagController.cs b/Core.Inventory.BFF.API/Controllers/TagController.cs index 2110dc8..2c61ea7 100644 --- a/Core.Inventory.BFF.API/Controllers/TagController.cs +++ b/Core.Inventory.BFF.API/Controllers/TagController.cs @@ -2,6 +2,7 @@ using Core.Adapters.Lib; using Core.Inventory.External.Clients.Inventory; using Core.Inventory.External.Clients.Inventory.Requests.Tag; +using Core.Inventory.External.Clients.Inventory.Requests.TagType; using Lib.Architecture.BuildingBlocks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -257,5 +258,34 @@ namespace Core.Inventory.BFF.API.Controllers throw; } } + + /// + /// Deletes a full Tag by identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteTagService(DeleteTagRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(DeleteTagService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); + + if (request == null) return BadRequest("Invalid Tag object"); + + if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid Tag identifier"); + + return await Handle(() => inventoryServiceClient.DeleteTagService(request, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(DeleteTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); + throw; + } + } } } diff --git a/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs b/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs index ef70cb3..37f80a6 100644 --- a/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs +++ b/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs @@ -2,6 +2,7 @@ using Core.Adapters.Lib; using Core.Inventory.External.Clients.Inventory; using Core.Inventory.External.Clients.Inventory.Requests.TagOverride; +using Core.Inventory.External.Clients.Inventory.Requests.TagType; using Lib.Architecture.BuildingBlocks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -202,6 +203,33 @@ namespace Core.Inventory.BFF.API.Controllers } } + /// + /// Deletes a full TagOverride by identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteTagOverrideService(DeleteTagOverrideRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(DeleteTagOverrideService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); + if (request == null) return BadRequest("Invalid TagOverride object"); + + if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid TagOverride identifier"); + + return await Handle(() => inventoryServiceClient.DeleteTagOverrideService(request, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(DeleteTagOverrideService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); + throw; + } + } } } diff --git a/Core.Inventory.BFF.API/Controllers/TagTypeController.cs b/Core.Inventory.BFF.API/Controllers/TagTypeController.cs index 174ab0d..1b6b853 100644 --- a/Core.Inventory.BFF.API/Controllers/TagTypeController.cs +++ b/Core.Inventory.BFF.API/Controllers/TagTypeController.cs @@ -198,6 +198,33 @@ namespace Core.Inventory.BFF.API.Controllers } } + /// + /// Deletes a full TagType by identifier. + /// + [HttpDelete("Delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] + [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteTagTypeService(DeleteTagTypeRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(DeleteTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); + if (request == null) return BadRequest("Invalid TagType object"); + + if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid TagType identifier"); + + return await Handle(() => inventoryServiceClient.DeleteTagTypeService(request, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(DeleteTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); + throw; + } + } } } diff --git a/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs index ba32fcb..d9c0e8c 100644 --- a/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs @@ -76,6 +76,9 @@ namespace Core.Inventory.External.Clients.Inventory [Patch("/api/v1/TagType/ChangeStatus")] Task> ChangeTagTypeStatusService([Header("TrackingId")][Body] ChangeTagTypeStatusRequest request, CancellationToken cancellationToken = default); + [Delete("/api/v1/TagType/Delete")] + Task> DeleteTagTypeService([Header("TrackingId")][Body] DeleteTagTypeRequest request, CancellationToken cancellationToken = default); + #endregion #region Tag @@ -104,6 +107,9 @@ namespace Core.Inventory.External.Clients.Inventory [Delete("/api/v1/Tag/RemoveParentTag")] Task> RemoveParentTagAsync([Header("TrackingId")][Body] RemoveParentTagFromTag request, CancellationToken cancellationToken = default); + [Delete("/api/v1/Tag/Delete")] + Task> DeleteTagService([Header("TrackingId")][Body] DeleteTagRequest request, CancellationToken cancellationToken = default); + #endregion #region TagOverride @@ -126,6 +132,9 @@ namespace Core.Inventory.External.Clients.Inventory [Patch("/api/v1/TagOverride/ChangeStatus")] Task> ChangeTagOverrideStatusService([Header("TrackingId")][Body] ChangeTagOverrideStatusRequest request, CancellationToken cancellationToken = default); + [Delete("/api/v1/TagOverride/Delete")] + Task> DeleteTagOverrideService([Header("TrackingId")][Body] DeleteTagOverrideRequest request, CancellationToken cancellationToken = default); + #endregion #region Product diff --git a/Core.Inventory.External/Clients/Inventory/Requests/Tag/DeleteTagRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/Tag/DeleteTagRequest.cs new file mode 100644 index 0000000..7c0ca81 --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/Tag/DeleteTagRequest.cs @@ -0,0 +1,14 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.External.Clients.Inventory.Requests.Tag +{ + public class DeleteTagRequest : 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/TagOverride/DeleteTagOverrideRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/DeleteTagOverrideRequest.cs new file mode 100644 index 0000000..02d3880 --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/DeleteTagOverrideRequest.cs @@ -0,0 +1,14 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class DeleteTagOverrideRequest : 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/TagType/DeleteTagTypeRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagType/DeleteTagTypeRequest.cs new file mode 100644 index 0000000..5cf994e --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagType/DeleteTagTypeRequest.cs @@ -0,0 +1,14 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.External.Clients.Inventory.Requests.TagType +{ + public class DeleteTagTypeRequest : Notificator, ICommand + { + public string Id { get; set; } = null!; + + public bool Validate() + { + return Id != null; + } + } +} \ No newline at end of file