From b4fbee29892f6a2746236e0334d55fb4d0b2b441 Mon Sep 17 00:00:00 2001 From: Oscar Morales Date: Tue, 5 Aug 2025 12:32:19 -0600 Subject: [PATCH] Add TagOverride CRUD --- .../Controllers/TagController.cs | 12 +- .../Controllers/TagOverrideController.cs | 207 ++++++++++++++++++ .../Controllers/TagTypeController.cs | 12 +- .../Inventory/IInventoryServiceClient.cs | 23 ++ .../ChangeTagOverrideStatusRequest.cs | 10 + .../TagOverride/CreateTagOverrideRequest.cs | 9 + .../GetAllTagOverridesByListRequest.cs | 7 + .../TagOverride/GetAllTagOverridesRequest.cs | 6 + .../TagOverride/GetTagOverrideRequest.cs | 7 + .../TagOverride/UpdateTagOverrideRequest.cs | 13 ++ 10 files changed, 294 insertions(+), 12 deletions(-) create mode 100644 Core.Inventory.BFF.API/Controllers/TagOverrideController.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/ChangeTagOverrideStatusRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/CreateTagOverrideRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesByListRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetTagOverrideRequest.cs create mode 100644 Core.Inventory.External/Clients/Inventory/Requests/TagOverride/UpdateTagOverrideRequest.cs diff --git a/Core.Inventory.BFF.API/Controllers/TagController.cs b/Core.Inventory.BFF.API/Controllers/TagController.cs index 4a12c2e..2110dc8 100644 --- a/Core.Inventory.BFF.API/Controllers/TagController.cs +++ b/Core.Inventory.BFF.API/Controllers/TagController.cs @@ -150,21 +150,21 @@ namespace Core.Inventory.BFF.API.Controllers [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task UpdateTagService(UpdateTagRequest newTag, CancellationToken cancellationToken) + public async Task UpdateTagService(UpdateTagRequest tag, CancellationToken cancellationToken) { try { - logger.LogInformation($"{nameof(UpdateTagService)} - Request received - Payload: {JsonSerializer.Serialize(newTag)}"); + logger.LogInformation($"{nameof(UpdateTagService)} - Request received - Payload: {JsonSerializer.Serialize(tag)}"); - if (newTag == null) return BadRequest("Invalid Tag object"); + if (tag == null) return BadRequest("Invalid Tag object"); - if (string.IsNullOrEmpty(newTag.TagName)) return BadRequest("Invalid Tag name"); + if (string.IsNullOrEmpty(tag.TagName)) return BadRequest("Invalid Tag name"); - return await Handle(() => inventoryServiceClient.UpdateTagService(newTag, cancellationToken)).ConfigureAwait(false); + return await Handle(() => inventoryServiceClient.UpdateTagService(tag, cancellationToken)).ConfigureAwait(false); } catch (Exception ex) { - logger.LogError($"{nameof(UpdateTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTag)}"); + logger.LogError($"{nameof(UpdateTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(tag)}"); throw; } } diff --git a/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs b/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs new file mode 100644 index 0000000..ef70cb3 --- /dev/null +++ b/Core.Inventory.BFF.API/Controllers/TagOverrideController.cs @@ -0,0 +1,207 @@ +using Asp.Versioning; +using Core.Adapters.Lib; +using Core.Inventory.External.Clients.Inventory; +using Core.Inventory.External.Clients.Inventory.Requests.TagOverride; +using Lib.Architecture.BuildingBlocks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Text.Json; + +namespace Core.Inventory.BFF.API.Controllers +{ + /// + /// Handles all requests for TagOverride authentication. + /// + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]")] + [Consumes("application/json")] + [Produces("application/json")] + [ApiController] + [AllowAnonymous] + public class TagOverrideController(IInventoryServiceClient inventoryServiceClient, ILogger logger) : BaseController(logger) + { + /// + /// Gets all the TagOverrides. + /// + [HttpGet("GetAll")] + [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 GetAllTagOverridesService(CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(GetAllTagOverridesService)} - Request received - Payload: "); + + return await Handle(() => inventoryServiceClient.GetAllTagOverridesService(new GetAllTagOverridesRequest { }, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(GetAllTagOverridesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); + throw; + } + } + + /// + /// Gets all the TagOverrides by TagOverride identifiers. + /// + /// The request containing the list of TagOverride identifiers. + /// Cancellation token for the asynchronous operation. + /// The representing the result of the service call. + /// The TagOverrides found. + /// No content if no TagOverrides are found. + /// Bad request if the TagOverride identifiers are missing or invalid. + /// Unauthorized if the user is not authenticated. + /// Internal server error if an unexpected error occurs. + [HttpPost("GetAllByList")] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetAllTagOverridesByListAsync([FromBody] GetAllTagOverridesByListRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(GetAllTagOverridesByListAsync)} - Request received - Payload: {request}"); + + if (request == null || request.TagOverrides == null || !request.TagOverrides.Any()) + { + return BadRequest("TagOverride identifiers are required."); + } + + return await Handle(() => inventoryServiceClient.GetAllTagOverridesByListService(request, cancellationToken)).ConfigureAwait(false); + + } + catch (Exception ex) + { + logger.LogError(ex, $"{nameof(GetAllTagOverridesByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}"); + return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); + } + } + + + /// + /// Creates a new TagOverride. + /// + [HttpPost("Create")] + [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 CreateTagOverrideService(CreateTagOverrideRequest newTagOverride, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(CreateTagOverrideService)} - Request received - Payload: {JsonSerializer.Serialize(newTagOverride)}"); + + if (newTagOverride == null) return BadRequest("Invalid TagOverride object"); + + if (string.IsNullOrEmpty(newTagOverride.BaseTagId)) return BadRequest("Invalid TagOverride BaseTagId"); + + if (string.IsNullOrEmpty(newTagOverride.OverrideTagId)) return BadRequest("Invalid TagOverride OverrideTagId"); + + return await Handle(() => inventoryServiceClient.CreateTagOverrideService(newTagOverride, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(CreateTagOverrideService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagOverride)}"); + throw; + } + } + + /// + /// Gets the TagOverride by identifier. + /// + [HttpPost("GetById")] + [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 GetTagOverrideByIdService(GetTagOverrideRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(GetTagOverrideByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); + + if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid TagOverride identifier"); + + return await Handle(() => inventoryServiceClient.GetTagOverrideByIdService(request, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(GetTagOverrideByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); + throw; + } + } + + /// + /// Updates a full TagOverride by identifier. + /// + [HttpPut("Update")] + [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 UpdateTagOverrideService(UpdateTagOverrideRequest tagOverride, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(UpdateTagOverrideService)} - Request received - Payload: {JsonSerializer.Serialize(tagOverride)}"); + + if (tagOverride == null) return BadRequest("Invalid TagOverride object"); + + if (string.IsNullOrEmpty(tagOverride.BaseTagId)) return BadRequest("Invalid TagOverride BaseTagId"); + + if (string.IsNullOrEmpty(tagOverride.OverrideTagId)) return BadRequest("Invalid TagOverride OverrideTagId"); + + return await Handle(() => inventoryServiceClient.UpdateTagOverrideService(tagOverride, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(UpdateTagOverrideService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(tagOverride)}"); + throw; + } + } + + /// + /// Changes the status of the TagOverride. + /// + [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 ChangeTagOverrideStatusService([FromBody] ChangeTagOverrideStatusRequest request, CancellationToken cancellationToken) + { + try + { + logger.LogInformation($"{nameof(ChangeTagOverrideStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); + + if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagOverride identifier"); } + + return await Handle(() => inventoryServiceClient.ChangeTagOverrideStatusService(request, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogError($"{nameof(ChangeTagOverrideStatusService)} - 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 eb12c18..174ab0d 100644 --- a/Core.Inventory.BFF.API/Controllers/TagTypeController.cs +++ b/Core.Inventory.BFF.API/Controllers/TagTypeController.cs @@ -150,21 +150,21 @@ namespace Core.Inventory.BFF.API.Controllers [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task UpdateTagTypeService(UpdateTagTypeRequest newTagType, CancellationToken cancellationToken) + public async Task UpdateTagTypeService(UpdateTagTypeRequest tagType, CancellationToken cancellationToken) { try { - logger.LogInformation($"{nameof(UpdateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(newTagType)}"); + logger.LogInformation($"{nameof(UpdateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(tagType)}"); - if (newTagType == null) return BadRequest("Invalid TagType object"); + if (tagType == null) return BadRequest("Invalid TagType object"); - if (string.IsNullOrEmpty(newTagType.TypeName)) return BadRequest("Invalid TagType name"); + if (string.IsNullOrEmpty(tagType.TypeName)) return BadRequest("Invalid TagType name"); - return await Handle(() => inventoryServiceClient.UpdateTagTypeService(newTagType, cancellationToken)).ConfigureAwait(false); + return await Handle(() => inventoryServiceClient.UpdateTagTypeService(tagType, cancellationToken)).ConfigureAwait(false); } catch (Exception ex) { - logger.LogError($"{nameof(UpdateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagType)}"); + logger.LogError($"{nameof(UpdateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(tagType)}"); throw; } } diff --git a/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs index 77fa443..902beb6 100644 --- a/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/Inventory/IInventoryServiceClient.cs @@ -3,6 +3,7 @@ using Core.Adapters.Lib.Inventory; using Core.Inventory.External.Clients.Inventory.Requests.Base; using Core.Inventory.External.Clients.Inventory.Requests.Product; using Core.Inventory.External.Clients.Inventory.Requests.Tag; +using Core.Inventory.External.Clients.Inventory.Requests.TagOverride; using Core.Inventory.External.Clients.Inventory.Requests.TagType; using Core.Inventory.External.Clients.Inventory.Requests.Variant; using Refit; @@ -105,6 +106,28 @@ namespace Core.Inventory.External.Clients.Inventory #endregion + #region TagOverride + + [Post("/api/v1/TagOverride/Create")] + Task> CreateTagOverrideService([Header("TrackingId")][Body] CreateTagOverrideRequest request, CancellationToken cancellationToken = default); + + [Post("/api/v1/TagOverride/GetById")] + Task> GetTagOverrideByIdService([Header("TrackingId")][Body] GetTagOverrideRequest request, CancellationToken cancellationToken = default); + + [Get("/api/v1/TagOverride/GetAll")] + Task>> GetAllTagOverridesService([Header("TrackingId")][Body] GetAllTagOverridesRequest request, CancellationToken cancellationToken = default); + + [Post("/api/v1/TagOverride/GetTagOverrideList")] + Task>> GetAllTagOverridesByListService([Header("TrackingId")][Body] GetAllTagOverridesByListRequest request, CancellationToken cancellationToken = default); + + [Put("/api/v1/TagOverride/Update")] + Task> UpdateTagOverrideService([Header("TrackingId")][Body] UpdateTagOverrideRequest request, CancellationToken cancellationToken = default); + + [Patch("/api/v1/TagOverride/ChangeStatus")] + Task> ChangeTagOverrideStatusService([Header("TrackingId")][Body] ChangeTagOverrideStatusRequest request, CancellationToken cancellationToken = default); + + #endregion + #region Product [Post("/api/v1/Product/Create")] diff --git a/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/ChangeTagOverrideStatusRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/ChangeTagOverrideStatusRequest.cs new file mode 100644 index 0000000..50defac --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/ChangeTagOverrideStatusRequest.cs @@ -0,0 +1,10 @@ +using Core.Blueprint.Mongo; + +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class ChangeTagOverrideStatusRequest + { + public string Id { get; set; } + public StatusEnum Status { get; set; } + } +} diff --git a/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/CreateTagOverrideRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/CreateTagOverrideRequest.cs new file mode 100644 index 0000000..b9f6b84 --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/CreateTagOverrideRequest.cs @@ -0,0 +1,9 @@ +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class CreateTagOverrideRequest + { + public string TenantId { get; set; } = null!; + public string BaseTagId { get; set; } = null!; + public string OverrideTagId { get; set; } = null!; + } +} diff --git a/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesByListRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesByListRequest.cs new file mode 100644 index 0000000..268480b --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesByListRequest.cs @@ -0,0 +1,7 @@ +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class GetAllTagOverridesByListRequest + { + public string[] TagOverrides { get; set; } + } +} diff --git a/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesRequest.cs new file mode 100644 index 0000000..db7d7aa --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetAllTagOverridesRequest.cs @@ -0,0 +1,6 @@ +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class GetAllTagOverridesRequest + { + } +} diff --git a/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetTagOverrideRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetTagOverrideRequest.cs new file mode 100644 index 0000000..07fdbf9 --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/GetTagOverrideRequest.cs @@ -0,0 +1,7 @@ +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class GetTagOverrideRequest + { + public string Id { get; set; } + } +} diff --git a/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/UpdateTagOverrideRequest.cs b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/UpdateTagOverrideRequest.cs new file mode 100644 index 0000000..b8ede2c --- /dev/null +++ b/Core.Inventory.External/Clients/Inventory/Requests/TagOverride/UpdateTagOverrideRequest.cs @@ -0,0 +1,13 @@ +using Core.Blueprint.Mongo; + +namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride +{ + public class UpdateTagOverrideRequest + { + 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 StatusEnum Status { get; set; } + } +}