From e6d68f4fd315fe6c2a60d2efe1cfef0be73136f4 Mon Sep 17 00:00:00 2001 From: Oscar Morales Date: Thu, 31 Jul 2025 19:07:40 -0600 Subject: [PATCH] Add TagType CRUD --- .../UseCases/TagType/Adapter/TagTypePort.cs | 19 ++ .../Input/ChangeTagTypeStatusRequest.cs | 16 ++ .../TagType/Input/CreateTagTypeRequest.cs | 17 ++ .../Input/GetAllTagTypesByListRequest.cs | 14 ++ .../TagType/Input/GetAllTagTypesRequest.cs | 12 + .../TagType/Input/GetTagTypeRequest.cs | 13 ++ .../TagType/Input/UpdateTagTypeRequest.cs | 22 ++ .../UseCases/TagType/Ports/ITagTypePort.cs | 14 ++ .../UseCases/TagType/TagTypeHandler.cs | 214 ++++++++++++++++++ .../Validator/ChangeTagTypeStatusValidator.cs | 14 ++ .../Validator/CreateTagTypeValidator.cs | 14 ++ .../GetAllTagTypesByListValidator.cs | 14 ++ .../Validator/UpdateTagTypeValidator.cs | 14 ++ .../Clients/IInventoryServiceClient.cs | 22 ++ .../Clients/Requests/TagTypeRequest.cs | 10 + .../Core.Inventory.External.csproj | 2 +- .../Controllers/TagTypeController.cs | 187 +++++++++++++++ .../Extensions/ServiceCollectionExtension.cs | 29 +++ 18 files changed, 646 insertions(+), 1 deletion(-) create mode 100644 Core.Inventory.Application/UseCases/TagType/Adapter/TagTypePort.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Input/ChangeTagTypeStatusRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Input/CreateTagTypeRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesByListRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Input/GetTagTypeRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Ports/ITagTypePort.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Validator/ChangeTagTypeStatusValidator.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Validator/CreateTagTypeValidator.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Validator/GetAllTagTypesByListValidator.cs create mode 100644 Core.Inventory.Application/UseCases/TagType/Validator/UpdateTagTypeValidator.cs create mode 100644 Core.Inventory.External/Clients/Requests/TagTypeRequest.cs create mode 100644 Core.Inventory.Service.API/Controllers/TagTypeController.cs diff --git a/Core.Inventory.Application/UseCases/TagType/Adapter/TagTypePort.cs b/Core.Inventory.Application/UseCases/TagType/Adapter/TagTypePort.cs new file mode 100644 index 0000000..b9b0eec --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Adapter/TagTypePort.cs @@ -0,0 +1,19 @@ +using Core.Adapters.Lib; +using Core.Inventory.Application.UseCases.TagType.Ports; +using Lib.Architecture.BuildingBlocks; +using Microsoft.AspNetCore.Mvc; + +namespace Core.Inventory.Application.UseCases.TagType.Adapter +{ + public class TagTypePort : BasePresenter, ITagTypePort + { + public void Success(TagTypeAdapter output) + { + ViewModel = new OkObjectResult(output); + } + public void Success(List output) + { + ViewModel = new OkObjectResult(output); + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Input/ChangeTagTypeStatusRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/ChangeTagTypeStatusRequest.cs new file mode 100644 index 0000000..a221e9b --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Input/ChangeTagTypeStatusRequest.cs @@ -0,0 +1,16 @@ +using Core.Blueprint.Mongo; +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagType.Input +{ + public class ChangeTagTypeStatusRequest : 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/TagType/Input/CreateTagTypeRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/CreateTagTypeRequest.cs new file mode 100644 index 0000000..bcb6fe3 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Input/CreateTagTypeRequest.cs @@ -0,0 +1,17 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagType.Input +{ + public class CreateTagTypeRequest : Notificator, ICommand + { + public string TenantId { get; set; } = null!; + public string TypeName { get; set; } = null!; + public int Level { get; set; } + public string ParentTypeId { get; set; } = null!; + + public bool Validate() + { + return TypeName != null; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesByListRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesByListRequest.cs new file mode 100644 index 0000000..c58de27 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesByListRequest.cs @@ -0,0 +1,14 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagType.Input +{ + public class GetAllTagTypesByListRequest : Notificator, ICommand + { + public string[] TagTypes { get; set; } + + public bool Validate() + { + return TagTypes != null; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesRequest.cs new file mode 100644 index 0000000..90ffdd7 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Input/GetAllTagTypesRequest.cs @@ -0,0 +1,12 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagType.Input +{ + public class GetAllTagTypesRequest : ICommand + { + public bool Validate() + { + return true; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Input/GetTagTypeRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/GetTagTypeRequest.cs new file mode 100644 index 0000000..f7959e3 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Input/GetTagTypeRequest.cs @@ -0,0 +1,13 @@ +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagType.Input +{ + public class GetTagTypeRequest : Notificator, ICommand + { + public string Id { get; set; } + public bool Validate() + { + return Id != null; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs b/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs new file mode 100644 index 0000000..03a9469 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Input/UpdateTagTypeRequest.cs @@ -0,0 +1,22 @@ +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 +{ + public class UpdateTagTypeRequest : Notificator, ICommand + { + public string Id { get; set; } = null!; + public string TenantId { get; set; } = null!; + public string TypeName { get; set; } = null!; + public int Level { get; set; } + public string ParentTypeId { get; set; } = null!; + public bool Validate() + { + return Id != null; + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Ports/ITagTypePort.cs b/Core.Inventory.Application/UseCases/TagType/Ports/ITagTypePort.cs new file mode 100644 index 0000000..1f73eb8 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Ports/ITagTypePort.cs @@ -0,0 +1,14 @@ +using Core.Adapters.Lib; +using Lib.Architecture.BuildingBlocks; + +namespace Core.Inventory.Application.UseCases.TagType.Ports +{ + public interface ITagTypePort : IBasePort, + ICommandSuccessPort, + ICommandSuccessPort>, + INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, + INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, + IBadRequestPort + { + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs b/Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs new file mode 100644 index 0000000..c3f4760 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs @@ -0,0 +1,214 @@ +using Core.Adapters.Lib; +using Core.Inventory.Application.UseCases.TagType.Input; +using Core.Inventory.Application.UseCases.TagType.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.TagType +{ + public class TagTypeHandler : + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler, + IComponentHandler + { + private readonly ITagTypePort _port; + private readonly IValidator _changeTagTypeStatusValidator; + private readonly IValidator _registerTagTypeValidator; + private readonly IValidator _updateTagTypeValidator; + private readonly IValidator _TagTypesByListValidator; + private readonly IInventoryServiceClient _inventoryServiceClient; + + public TagTypeHandler( + ITagTypePort port, + IValidator changeTagTypeStatusValidator, + IValidator registerTagTypeValidator, + IValidator updateTagTypeValidator, + IValidator TagTypesByListValidator, + IInventoryServiceClient inventoryDALService) + { + _port = port ?? throw new ArgumentNullException(nameof(port)); + _changeTagTypeStatusValidator = changeTagTypeStatusValidator ?? throw new ArgumentNullException(nameof(changeTagTypeStatusValidator)); + _registerTagTypeValidator = registerTagTypeValidator ?? throw new ArgumentNullException(nameof(registerTagTypeValidator)); + _updateTagTypeValidator = updateTagTypeValidator ?? throw new ArgumentNullException(nameof(updateTagTypeValidator)); + _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); + _TagTypesByListValidator = TagTypesByListValidator ?? throw new ArgumentNullException(nameof(TagTypesByListValidator)); + } + + public async ValueTask ExecuteAsync(GetTagTypeRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + var result = await _inventoryServiceClient.GetTagTypeByIdAsync(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(GetAllTagTypesRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + var _result = await _inventoryServiceClient.GetAllTagTypesAsync().ConfigureAwait(false); + if (!_result.Any()) + { + _port.NoContentSuccess(); + return; + } + _port.Success(_result.ToList()); + } + catch (Exception ex) + { + ApiResponseHelper.EvaluatePort(ex, _port); + } + } + + public async ValueTask ExecuteAsync(GetAllTagTypesByListRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + if (!command.IsValid(_TagTypesByListValidator)) + { + _port.ValidationErrors(command.Notifications); + return; + } + + var _result = await _inventoryServiceClient.GetAllTagTypesByListAsync(command.TagTypes, cancellationToken).ConfigureAwait(false); + if (!_result.Any()) + { + _port.NoContentSuccess(); + return; + } + _port.Success(_result.ToList()); + } + catch (Exception ex) + { + ApiResponseHelper.EvaluatePort(ex, _port); + } + } + + public async ValueTask ExecuteAsync(ChangeTagTypeStatusRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + if (!command.IsValid(_changeTagTypeStatusValidator)) + { + _port.ValidationErrors(command.Notifications); + return; + } + + var result = await _inventoryServiceClient.ChangeStatusTagTypeAsync(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(CreateTagTypeRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + if (!command.IsValid(_registerTagTypeValidator)) + { + _port.ValidationErrors(command.Notifications); + return; + } + + var request = new TagTypeRequest + { + TenantId = command.TenantId, + TypeName = command.TypeName, + Level = command.Level, + ParentTypeId = command.ParentTypeId, + }; + + var result = await _inventoryServiceClient.CreateTagTypeAsync(request, cancellationToken).ConfigureAwait(false); + + if (result == null) + { + _port.NoContentSuccess(); + return; + } + + _port.Success(result); + } + catch (Exception ex) + { + ApiResponseHelper.EvaluatePort(ex, _port); + } + } + + public async ValueTask ExecuteAsync(UpdateTagTypeRequest command, CancellationToken cancellationToken = default) + { + try + { + ArgumentNullException.ThrowIfNull(command); + + if (!command.IsValid(_updateTagTypeValidator)) + { + _port.ValidationErrors(command.Notifications); + return; + } + + var request = new TagTypeAdapter + { + Id = command.Id, + TenantId = command.TenantId, + TypeName = command.TypeName, + Level = command.Level, + ParentTypeId = command.ParentTypeId + }; + + string id = command.Id; + + var result = await _inventoryServiceClient.UpdateTagTypeAsync(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/TagType/Validator/ChangeTagTypeStatusValidator.cs b/Core.Inventory.Application/UseCases/TagType/Validator/ChangeTagTypeStatusValidator.cs new file mode 100644 index 0000000..c02f36c --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Validator/ChangeTagTypeStatusValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagType.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagType.Validator +{ + public class ChangeTagTypeStatusValidator : AbstractValidator + { + public ChangeTagTypeStatusValidator() + { + RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagType ID").WithMessage("TagType 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/TagType/Validator/CreateTagTypeValidator.cs b/Core.Inventory.Application/UseCases/TagType/Validator/CreateTagTypeValidator.cs new file mode 100644 index 0000000..5f7db59 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Validator/CreateTagTypeValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagType.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagType.Validator +{ + public class CreateTagTypeValidator : AbstractValidator + { + public CreateTagTypeValidator() + { + RuleFor(i => i.TypeName).NotEmpty().NotNull().OverridePropertyName(x => x.TypeName).WithName("TagType Name").WithMessage("TagType Name is Obligatory."); + RuleFor(i => i.Level).NotEmpty().NotNull().OverridePropertyName(x => x.Level).WithName("TagType Level").WithMessage("TagType Level is Obligatory."); + } + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Validator/GetAllTagTypesByListValidator.cs b/Core.Inventory.Application/UseCases/TagType/Validator/GetAllTagTypesByListValidator.cs new file mode 100644 index 0000000..0fceb0d --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Validator/GetAllTagTypesByListValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagType.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagType.Validator +{ + public class GetAllTagTypesByListValidator : AbstractValidator + { + public GetAllTagTypesByListValidator() + { + RuleFor(i => i.TagTypes).NotEmpty().NotNull().OverridePropertyName(x => x.TagTypes).WithName("TagTypes").WithMessage("TagTypes are Obligatory."); + } + + } +} diff --git a/Core.Inventory.Application/UseCases/TagType/Validator/UpdateTagTypeValidator.cs b/Core.Inventory.Application/UseCases/TagType/Validator/UpdateTagTypeValidator.cs new file mode 100644 index 0000000..c02ac83 --- /dev/null +++ b/Core.Inventory.Application/UseCases/TagType/Validator/UpdateTagTypeValidator.cs @@ -0,0 +1,14 @@ +using Core.Inventory.Application.UseCases.TagType.Input; +using FluentValidation; + +namespace Core.Inventory.Application.UseCases.TagType.Validator +{ + public class UpdateTagTypeValidator : AbstractValidator + { + public UpdateTagTypeValidator() + { + RuleFor(i => i.TypeName).NotEmpty().NotNull().OverridePropertyName(x => x.TypeName).WithName("TagType Name").WithMessage("TagType Name is Obligatory."); + RuleFor(i => i.Level).NotEmpty().NotNull().OverridePropertyName(x => x.Level).WithName("Level").WithMessage("Level is Obligatory."); + } + } +} diff --git a/Core.Inventory.External/Clients/IInventoryServiceClient.cs b/Core.Inventory.External/Clients/IInventoryServiceClient.cs index 1a5eb34..d7bf872 100644 --- a/Core.Inventory.External/Clients/IInventoryServiceClient.cs +++ b/Core.Inventory.External/Clients/IInventoryServiceClient.cs @@ -51,5 +51,27 @@ namespace Core.Inventory.External.Clients [Get("/api/v1/FurnitureVariant")] Task> GetAllFurnitureVariantAsync(CancellationToken cancellationToken = default); #endregion + + #region TagType + + [Get("/api/v1/TagType")] + Task> GetAllTagTypesAsync(CancellationToken cancellationToken = default); + + [Post("/api/v1/TagType/GetTagTypeList")] + Task> GetAllTagTypesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); + + [Get("/api/v1/TagType/{id}")] + Task GetTagTypeByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); + + [Post("/api/v1/TagType")] + Task CreateTagTypeAsync([FromBody] TagTypeRequest newTagType, CancellationToken cancellationToken = default); + + [Put("/api/v1/TagType/{id}")] + Task UpdateTagTypeAsync([FromBody] TagTypeAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); + + [Patch("/api/v1/TagType/{id}/{newStatus}/ChangeStatus")] + Task ChangeStatusTagTypeAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); + + #endregion } } diff --git a/Core.Inventory.External/Clients/Requests/TagTypeRequest.cs b/Core.Inventory.External/Clients/Requests/TagTypeRequest.cs new file mode 100644 index 0000000..e8fd3e5 --- /dev/null +++ b/Core.Inventory.External/Clients/Requests/TagTypeRequest.cs @@ -0,0 +1,10 @@ +namespace Core.Inventory.External.Clients.Requests +{ + public class TagTypeRequest + { + public string TenantId { get; set; } = null!; + public string TypeName { get; set; } = null!; + public int Level { get; set; } + public string ParentTypeId { get; set; } = null!; + } +} diff --git a/Core.Inventory.External/Core.Inventory.External.csproj b/Core.Inventory.External/Core.Inventory.External.csproj index c7d4c05..fdaf460 100644 --- a/Core.Inventory.External/Core.Inventory.External.csproj +++ b/Core.Inventory.External/Core.Inventory.External.csproj @@ -7,7 +7,7 @@ - + diff --git a/Core.Inventory.Service.API/Controllers/TagTypeController.cs b/Core.Inventory.Service.API/Controllers/TagTypeController.cs new file mode 100644 index 0000000..1011f30 --- /dev/null +++ b/Core.Inventory.Service.API/Controllers/TagTypeController.cs @@ -0,0 +1,187 @@ +using Asp.Versioning; +using Core.Adapters.Lib; +using Core.Inventory.Application.UseCases.TagType.Input; +using Core.Inventory.Application.UseCases.TagType.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 TagTypeController : ControllerBase + { + private readonly IComponentHandler getTagTypeHandler; + private readonly IComponentHandler getAllTagTypesHandler; + private readonly IComponentHandler getAllTagTypesByListHandler; + private readonly IComponentHandler createTagTypeHandler; + private readonly IComponentHandler updateTagTypeHandler; + private readonly IComponentHandler changeTagTypeStatusHandler; + private readonly ITagTypePort port; + + /// + /// Handles all services and business rules related to . + /// + public TagTypeController( + IComponentHandler getTagTypeHandler, + IComponentHandler getAllTagTypesHandler, + IComponentHandler getAllTagTypesByListHandler, + IComponentHandler createTagTypeHandler, + IComponentHandler updateTagTypeHandler, + IComponentHandler changeTagTypeStatusHandler, + ITagTypePort port + ) + { + this.createTagTypeHandler = createTagTypeHandler; + this.updateTagTypeHandler = updateTagTypeHandler; + this.changeTagTypeStatusHandler = changeTagTypeStatusHandler; + this.getAllTagTypesHandler = getAllTagTypesHandler; + this.getTagTypeHandler = getTagTypeHandler; + this.getAllTagTypesByListHandler = getAllTagTypesByListHandler; + this.port = port; + } + + /// + /// Gets all the TagTypes. + /// + [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 GetAllTagTypesAsync(CancellationToken cancellationToken) + { + await getAllTagTypesHandler.ExecuteAsync(new GetAllTagTypesRequest { }, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Gets all the TagTypes by TagType identifiers. + /// + /// The request containing the list of TagType identifiers. + /// Cancellation token for the asynchronous operation. + /// The representing the result of the service call. + /// The TagTypes found. + /// No content if no TagTypes are found. + /// Bad request if the TagType 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("GetTagTypeList")] + [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 GetAllTagTypesByListAsync([FromBody] GetAllTagTypesByListRequest request, CancellationToken cancellationToken) + { + + if (request == null || request.TagTypes == null || !request.TagTypes.Any()) + { + return BadRequest("TagType identifiers are required."); + } + + await getAllTagTypesByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Gets the TagType 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 GetTagTypeById([FromBody] GetTagTypeRequest request, CancellationToken cancellationToken) + { + + if (request.Id == null || !request.Id.Any()) + { + return BadRequest("Invalid TagType Id"); + } + + await getTagTypeHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Creates a new TagType. + /// + [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 CreateTagTypeAsync([FromBody] CreateTagTypeRequest newTagType, CancellationToken cancellationToken = default) + { + await createTagTypeHandler.ExecuteAsync(newTagType, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Updates a full TagType 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 UpdateTagTypeAsync([FromBody] UpdateTagTypeRequest request, CancellationToken cancellationToken = default) + { + await updateTagTypeHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + + return port.ViewModel; + } + + /// + /// Changes the status of the TagType. + /// + [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 ChangeTagTypeStatusAsync([FromBody] ChangeTagTypeStatusRequest request, + CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagType identifier"); } + + await changeTagTypeStatusHandler.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 5d3b226..ea386b4 100644 --- a/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs +++ b/Core.Inventory.Service.API/Extensions/ServiceCollectionExtension.cs @@ -5,6 +5,11 @@ using Core.Inventory.Application.UseCases.Inventory.Input.Variant; using Core.Inventory.Application.UseCases.Inventory.Ports; using Core.Inventory.Application.UseCases.Inventory.Validator.Base; using Core.Inventory.Application.UseCases.Inventory.Validator.Variant; +using Core.Inventory.Application.UseCases.TagType; +using Core.Inventory.Application.UseCases.TagType.Adapter; +using Core.Inventory.Application.UseCases.TagType.Input; +using Core.Inventory.Application.UseCases.TagType.Ports; +using Core.Inventory.Application.UseCases.TagType.Validator; using FluentValidation; using Lib.Architecture.BuildingBlocks; @@ -66,6 +71,30 @@ namespace Core.Inventory.Service.API.Extensions services.AddScoped, GetFurnitureVariantsByIdsValidator>(); #endregion + #region TagType Services + + services.AddScoped(); + services.AddScoped, TagTypeHandler>(); + services.AddScoped, TagTypeHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, GetAllTagTypesByListValidator>(); + services.AddScoped, TagTypeHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, CreateTagTypeValidator>(); + services.AddScoped, TagTypeHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, UpdateTagTypeValidator>(); + services.AddScoped, TagTypeHandler>(); + + services.AddValidatorsFromAssemblyContaining(); + services.AddScoped, ChangeTagTypeStatusValidator>(); + services.AddScoped, TagTypeHandler>(); + + #endregion + return services; } }