From 85e186396d6e2879c1263e66aad41767231c59e5 Mon Sep 17 00:00:00 2001 From: Oscar Morales Date: Tue, 5 Aug 2025 12:31:51 -0600 Subject: [PATCH] Add TagOverride CRUD --- .../TagOverride/Adapter/TagOverridePort.cs | 19 ++ .../Input/ChangeTagOverrideStatusRequest.cs | 16 ++ .../Input/CreateTagOverrideRequest.cs | 16 ++ .../Input/GetAllTagOverridesByListRequest.cs | 14 ++ .../Input/GetAllTagOverridesRequest.cs | 12 + .../Input/GetTagOverrideRequest.cs | 13 ++ .../Input/UpdateTagOverrideRequest.cs | 16 ++ .../TagOverride/Ports/ITagOverridePort.cs | 14 ++ .../TagOverride/TagOverrideHandler.cs | 212 ++++++++++++++++++ .../ChangeTagOverrideStatusValidator.cs | 14 ++ .../Validator/CreateTagOverrideValidator.cs | 14 ++ .../GetAllTagOverridesByListValidator.cs | 14 ++ .../Validator/UpdateTagOverrideValidator.cs | 14 ++ .../TagType/Input/UpdateTagTypeRequest.cs | 5 - .../Clients/IInventoryServiceClient.cs | 22 ++ .../Clients/Requests/TagOverrideRequest.cs | 9 + .../Controllers/TagOverrideController.cs | 187 +++++++++++++++ .../Extensions/ServiceCollectionExtension.cs | 29 +++ 18 files changed, 635 insertions(+), 5 deletions(-) create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Adapter/TagOverridePort.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Input/ChangeTagOverrideStatusRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Input/CreateTagOverrideRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesByListRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Input/GetTagOverrideRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Input/UpdateTagOverrideRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Ports/ITagOverridePort.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/TagOverrideHandler.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Validator/ChangeTagOverrideStatusValidator.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Validator/CreateTagOverrideValidator.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Validator/GetAllTagOverridesByListValidator.cs create mode 100644 Core.Inventory.Application/UseCases/TagOverride/Validator/UpdateTagOverrideValidator.cs create mode 100644 Core.Inventory.External/Clients/Requests/TagOverrideRequest.cs create mode 100644 Core.Inventory.Service.API/Controllers/TagOverrideController.cs diff --git a/Core.Inventory.Application/UseCases/TagOverride/Adapter/TagOverridePort.cs b/Core.Inventory.Application/UseCases/TagOverride/Adapter/TagOverridePort.cs new file mode 100644 index 0000000..4692682 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Adapter/TagOverridePort.cs @@ -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 output) + { + ViewModel = new OkObjectResult(output); + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Input/ChangeTagOverrideStatusRequest.cs b/Core.Inventory.Application/UseCases/TagOverride/Input/ChangeTagOverrideStatusRequest.cs new file mode 100644 index 0000000..b6c0ace --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Input/ChangeTagOverrideStatusRequest.cs @@ -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; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Input/CreateTagOverrideRequest.cs b/Core.Inventory.Application/UseCases/TagOverride/Input/CreateTagOverrideRequest.cs new file mode 100644 index 0000000..82c775c --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Input/CreateTagOverrideRequest.cs @@ -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; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesByListRequest.cs b/Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesByListRequest.cs new file mode 100644 index 0000000..2358f26 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesByListRequest.cs @@ -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; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesRequest.cs b/Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesRequest.cs new file mode 100644 index 0000000..2620360 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Input/GetAllTagOverridesRequest.cs @@ -0,0 +1,12 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagOverride.Input +{ + public class GetAllTagOverridesRequest : ICommand + { + public bool Validate() + { + return true; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Input/GetTagOverrideRequest.cs b/Core.Inventory.Application/UseCases/TagOverride/Input/GetTagOverrideRequest.cs new file mode 100644 index 0000000..bcf6c09 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Input/GetTagOverrideRequest.cs @@ -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; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Input/UpdateTagOverrideRequest.cs b/Core.Inventory.Application/UseCases/TagOverride/Input/UpdateTagOverrideRequest.cs new file mode 100644 index 0000000..97c8f05 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Input/UpdateTagOverrideRequest.cs @@ -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; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Ports/ITagOverridePort.cs b/Core.Inventory.Application/UseCases/TagOverride/Ports/ITagOverridePort.cs new file mode 100644 index 0000000..5414c91 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Ports/ITagOverridePort.cs @@ -0,0 +1,14 @@ +using Core.Adapters.Lib; +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagOverride.Ports +{ + public interface ITagOverridePort : IBasePort, + ICommandSuccessPort, + ICommandSuccessPort>, + INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, + INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, + IBadRequestPort + { + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/TagOverrideHandler.cs b/Core.Inventory.Application/UseCases/TagOverride/TagOverrideHandler.cs new file mode 100644 index 0000000..64351e3 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/TagOverrideHandler.cs @@ -0,0 +1,212 @@ +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, + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler + { + private readonly ITagOverridePort _port; + private readonly IValidator _changeTagOverrideStatusValidator; + private readonly IValidator _registerTagOverrideValidator; + private readonly IValidator _updateTagOverrideValidator; + private readonly IValidator _TagOverridesByListValidator; + private readonly IInventoryServiceClient _inventoryServiceClient; + + public TagOverrideHandler( + ITagOverridePort port, + IValidator changeTagOverrideStatusValidator, + IValidator registerTagOverrideValidator, + IValidator updateTagOverrideValidator, + IValidator TagOverridesByListValidator, + 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)); + } + + 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); + } + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Validator/ChangeTagOverrideStatusValidator.cs b/Core.Inventory.Application/UseCases/TagOverride/Validator/ChangeTagOverrideStatusValidator.cs new file mode 100644 index 0000000..f1029f8 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Validator/ChangeTagOverrideStatusValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagOverride.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagOverride.Validator +{ + public class ChangeTagOverrideStatusValidator : AbstractValidator + { + 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."); + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Validator/CreateTagOverrideValidator.cs b/Core.Inventory.Application/UseCases/TagOverride/Validator/CreateTagOverrideValidator.cs new file mode 100644 index 0000000..5a05f9e --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Validator/CreateTagOverrideValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagOverride.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagOverride.Validator +{ + public class CreateTagOverrideValidator : AbstractValidator + { + 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."); + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Validator/GetAllTagOverridesByListValidator.cs b/Core.Inventory.Application/UseCases/TagOverride/Validator/GetAllTagOverridesByListValidator.cs new file mode 100644 index 0000000..593a688 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Validator/GetAllTagOverridesByListValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagOverride.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagOverride.Validator +{ + public class GetAllTagOverridesByListValidator : AbstractValidator + { + public GetAllTagOverridesByListValidator() + { + RuleFor(i => i.TagOverrides).NotEmpty().NotNull().OverridePropertyName(x => x.TagOverrides).WithName("TagOverrides").WithMessage("TagOverrides are Obligatory."); + } + + } +} diff --git a/Core.Inventory.Application/UseCases/TagOverride/Validator/UpdateTagOverrideValidator.cs b/Core.Inventory.Application/UseCases/TagOverride/Validator/UpdateTagOverrideValidator.cs new file mode 100644 index 0000000..d4cb261 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagOverride/Validator/UpdateTagOverrideValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagOverride.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagOverride.Validator +{ + public class UpdateTagOverrideValidator : AbstractValidator + { + 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."); + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs index 03a9469..de03318 100644 --- a/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs +++ b/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs @@ -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 { diff --git a/Core.Inventory.External/Clients/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/IInventoryServiceClient.cs index 72c254c..bb6d81a 100644 --- a/Core.Inventory.External/Clients/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/IInventoryServiceClient.cs @@ -103,6 +103,28 @@ namespace Core.Inventory.External.Clients #endregion + #region TagOverride + + [Get("/api/v1/TagOverride")] + Task> GetAllTagOverridesAsync(CancellationToken cancellationToken = default); + + [Post("/api/v1/TagOverride/GetTagOverrideList")] + Task> GetAllTagOverridesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); + + [Get("/api/v1/TagOverride/{id}")] + Task GetTagOverrideByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + + [Post("/api/v1/TagOverride")] + Task CreateTagOverrideAsync([FromBody] TagOverrideRequest newTagOverride, CancellationToken cancellationToken = default); + + [Put("/api/v1/TagOverride/{id}")] + Task UpdateTagOverrideAsync([FromBody] TagOverrideAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); + + [Patch("/api/v1/TagOverride/{id}/{newStatus}/ChangeStatus")] + Task ChangeStatusTagOverrideAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); + + #endregion + #region Product [Get("/api/v1/Product")] diff --git a/Core.Inventory.External/Clients/Requests/TagOverrideRequest.cs b/Core.Inventory.External/Clients/Requests/TagOverrideRequest.cs new file mode 100644 index 0000000..6fc8127 --- /dev/null +++ b/Core.Inventory.External/Clients/Requests/TagOverrideRequest.cs @@ -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!; + } +} diff --git a/Core.Inventory.Service.API/Controllers/TagOverrideController.cs b/Core.Inventory.Service.API/Controllers/TagOverrideController.cs new file mode 100644 index 0000000..3ccd475 --- /dev/null +++ b/Core.Inventory.Service.API/Controllers/TagOverrideController.cs @@ -0,0 +1,187 @@ +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 +{ + /// + /// Handles all services and business rules related to . + /// + [ApiVersion("1.0")] + [Route("api/v{api-version:apiVersion}/[controller]")] + [Produces("application/json")] + [ApiController] + [AllowAnonymous] + public class TagOverrideController : ControllerBase + { + private readonly IComponentHandler getTagOverrideHandler; + private readonly IComponentHandler getAllTagOverridesHandler; + private readonly IComponentHandler getAllTagOverridesByListHandler; + private readonly IComponentHandler createTagOverrideHandler; + private readonly IComponentHandler updateTagOverrideHandler; + private readonly IComponentHandler changeTagOverrideStatusHandler; + private readonly ITagOverridePort port; + + /// + /// Handles all services and business rules related to . + /// + public TagOverrideController( + IComponentHandler getTagOverrideHandler, + IComponentHandler getAllTagOverridesHandler, + IComponentHandler getAllTagOverridesByListHandler, + IComponentHandler createTagOverrideHandler, + IComponentHandler updateTagOverrideHandler, + IComponentHandler changeTagOverrideStatusHandler, + ITagOverridePort port + ) + { + this.createTagOverrideHandler = createTagOverrideHandler; + this.updateTagOverrideHandler = updateTagOverrideHandler; + this.changeTagOverrideStatusHandler = changeTagOverrideStatusHandler; + this.getAllTagOverridesHandler = getAllTagOverridesHandler; + this.getTagOverrideHandler = getTagOverrideHandler; + this.getAllTagOverridesByListHandler = getAllTagOverridesByListHandler; + this.port = port; + } + + /// + /// Gets all the TagOverrides. + /// + [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 GetAllTagOverridesAsync(CancellationToken cancellationToken) + { + await getAllTagOverridesHandler.ExecuteAsync(new GetAllTagOverridesRequest { }, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// 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. + /// 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. + [HttpPost] + [Route("GetTagOverrideList")] + [ProducesResponseType(typeof(IEnumerable), 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 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; + } + + /// + /// Gets the TagOverride by identifier. + /// + [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 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; + } + + /// + /// Creates a new TagOverride. + /// + [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 CreateTagOverrideAsync([FromBody] CreateTagOverrideRequest newTagOverride, CancellationToken cancellationToken = default) + { + await createTagOverrideHandler.ExecuteAsync(newTagOverride, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Updates a full TagOverride by identifier. + /// + [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 UpdateTagOverrideAsync([FromBody] UpdateTagOverrideRequest request, CancellationToken cancellationToken = default) + { + await updateTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// 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 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; + } + } +} diff --git a/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs b/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs index bfbd1b6..216d66b 100644 --- a/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs +++ b/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs @@ -15,6 +15,11 @@ 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; @@ -132,6 +137,30 @@ namespace Core.Inventory.Service.API.Extensions #endregion + #region TagOverride Services + + services.AddScoped(); + services.AddScoped, TagOverrideHandler>(); + services.AddScoped, TagOverrideHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, GetAllTagOverridesByListValidator>(); + services.AddScoped, TagOverrideHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, CreateTagOverrideValidator>(); + services.AddScoped, TagOverrideHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, UpdateTagOverrideValidator>(); + services.AddScoped, TagOverrideHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, ChangeTagOverrideStatusValidator>(); + services.AddScoped, TagOverrideHandler>(); + + #endregion + #region Product Services services.AddScoped();