Add TagType CRUD #1
| @@ -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<TagTypeAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Input | ||||
| { | ||||
|     public class GetAllTagTypesRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Ports | ||||
| { | ||||
|     public interface ITagTypePort : IBasePort, | ||||
|         ICommandSuccessPort<TagTypeAdapter>, | ||||
|         ICommandSuccessPort<List<TagTypeAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										214
									
								
								Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										214
									
								
								Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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<ChangeTagTypeStatusRequest>, | ||||
|         IComponentHandler<GetAllTagTypesRequest>, | ||||
|         IComponentHandler<GetAllTagTypesByListRequest>, | ||||
|         IComponentHandler<UpdateTagTypeRequest>, | ||||
|         IComponentHandler<GetTagTypeRequest>, | ||||
|         IComponentHandler<CreateTagTypeRequest> | ||||
|     { | ||||
|         private readonly ITagTypePort _port; | ||||
|         private readonly IValidator<ChangeTagTypeStatusRequest> _changeTagTypeStatusValidator; | ||||
|         private readonly IValidator<CreateTagTypeRequest> _registerTagTypeValidator; | ||||
|         private readonly IValidator<UpdateTagTypeRequest> _updateTagTypeValidator; | ||||
|         private readonly IValidator<GetAllTagTypesByListRequest> _TagTypesByListValidator; | ||||
|         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||
|  | ||||
|         public TagTypeHandler( | ||||
|             ITagTypePort port, | ||||
|             IValidator<ChangeTagTypeStatusRequest> changeTagTypeStatusValidator, | ||||
|             IValidator<CreateTagTypeRequest> registerTagTypeValidator, | ||||
|             IValidator<UpdateTagTypeRequest> updateTagTypeValidator, | ||||
|             IValidator<GetAllTagTypesByListRequest> 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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Validator | ||||
| { | ||||
|     public class ChangeTagTypeStatusValidator : AbstractValidator<ChangeTagTypeStatusRequest> | ||||
|     { | ||||
|         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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Validator | ||||
| { | ||||
|     public class CreateTagTypeValidator : AbstractValidator<CreateTagTypeRequest> | ||||
|     { | ||||
|         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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Validator | ||||
| { | ||||
|     public class GetAllTagTypesByListValidator : AbstractValidator<GetAllTagTypesByListRequest> | ||||
|     { | ||||
|         public GetAllTagTypesByListValidator() | ||||
|         { | ||||
|             RuleFor(i => i.TagTypes).NotEmpty().NotNull().OverridePropertyName(x => x.TagTypes).WithName("TagTypes").WithMessage("TagTypes are Obligatory."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Validator | ||||
| { | ||||
|     public class UpdateTagTypeValidator : AbstractValidator<UpdateTagTypeRequest> | ||||
|     { | ||||
|         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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -51,5 +51,27 @@ namespace Core.Inventory.External.Clients | ||||
|         [Get("/api/v1/FurnitureVariant")] | ||||
|         Task<IEnumerable<FurnitureVariant>> GetAllFurnitureVariantAsync(CancellationToken cancellationToken = default); | ||||
|         #endregion | ||||
|  | ||||
|         #region TagType | ||||
|  | ||||
|         [Get("/api/v1/TagType")] | ||||
|         Task<IEnumerable<TagTypeAdapter>> GetAllTagTypesAsync(CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/TagType/GetTagTypeList")] | ||||
|         Task<IEnumerable<TagTypeAdapter>> GetAllTagTypesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Get("/api/v1/TagType/{id}")] | ||||
|         Task<TagTypeAdapter> GetTagTypeByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/TagType")] | ||||
|         Task<TagTypeAdapter> CreateTagTypeAsync([FromBody] TagTypeRequest newTagType, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Put("/api/v1/TagType/{id}")] | ||||
|         Task<TagTypeAdapter> UpdateTagTypeAsync([FromBody] TagTypeAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Patch("/api/v1/TagType/{id}/{newStatus}/ChangeStatus")] | ||||
|         Task<TagTypeAdapter> ChangeStatusTagTypeAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										10
									
								
								Core.Inventory.External/Clients/Requests/TagTypeRequest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Core.Inventory.External/Clients/Requests/TagTypeRequest.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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!; | ||||
|     } | ||||
| } | ||||
| @@ -7,7 +7,7 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Adapters.Lib" Version="1.0.6" /> | ||||
|     <PackageReference Include="Adapters.Lib" Version="1.0.9" /> | ||||
|     <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> | ||||
|     <PackageReference Include="Refit" Version="8.0.0" /> | ||||
|   </ItemGroup> | ||||
|   | ||||
							
								
								
									
										187
									
								
								Core.Inventory.Service.API/Controllers/TagTypeController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								Core.Inventory.Service.API/Controllers/TagTypeController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="TagTypeController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [AllowAnonymous] | ||||
|     public class TagTypeController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetTagTypeRequest> getTagTypeHandler; | ||||
|         private readonly IComponentHandler<GetAllTagTypesRequest> getAllTagTypesHandler; | ||||
|         private readonly IComponentHandler<GetAllTagTypesByListRequest> getAllTagTypesByListHandler; | ||||
|         private readonly IComponentHandler<CreateTagTypeRequest> createTagTypeHandler; | ||||
|         private readonly IComponentHandler<UpdateTagTypeRequest> updateTagTypeHandler; | ||||
|         private readonly IComponentHandler<ChangeTagTypeStatusRequest> changeTagTypeStatusHandler; | ||||
|         private readonly ITagTypePort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="TagTypeController"/>. | ||||
|         /// </summary> | ||||
|         public TagTypeController( | ||||
|             IComponentHandler<GetTagTypeRequest> getTagTypeHandler, | ||||
|             IComponentHandler<GetAllTagTypesRequest> getAllTagTypesHandler, | ||||
|             IComponentHandler<GetAllTagTypesByListRequest> getAllTagTypesByListHandler, | ||||
|             IComponentHandler<CreateTagTypeRequest> createTagTypeHandler, | ||||
|             IComponentHandler<UpdateTagTypeRequest> updateTagTypeHandler, | ||||
|             IComponentHandler<ChangeTagTypeStatusRequest> changeTagTypeStatusHandler, | ||||
|             ITagTypePort port | ||||
|             ) | ||||
|         { | ||||
|             this.createTagTypeHandler = createTagTypeHandler; | ||||
|             this.updateTagTypeHandler = updateTagTypeHandler; | ||||
|             this.changeTagTypeStatusHandler = changeTagTypeStatusHandler; | ||||
|             this.getAllTagTypesHandler = getAllTagTypesHandler; | ||||
|             this.getTagTypeHandler = getTagTypeHandler; | ||||
|             this.getAllTagTypesByListHandler = getAllTagTypesByListHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the TagTypes. | ||||
|         /// </summary> | ||||
|         [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<IActionResult> GetAllTagTypesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllTagTypesHandler.ExecuteAsync(new GetAllTagTypesRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the TagTypes by TagType identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of TagType identifiers.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The TagTypes found.</response> | ||||
|         /// <response code="204">No content if no TagTypes are found.</response> | ||||
|         /// <response code="400">Bad request if the TagType identifiers are missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost] | ||||
|         [Route("GetTagTypeList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<TagTypeAdapter>), 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<IActionResult> 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; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the TagType by identifier. | ||||
|         /// </summary> | ||||
|         [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<IActionResult> 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; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new TagType. | ||||
|         /// </summary> | ||||
|         [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<IActionResult> CreateTagTypeAsync([FromBody] CreateTagTypeRequest newTagType, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createTagTypeHandler.ExecuteAsync(newTagType, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full TagType by identifier. | ||||
|         /// </summary> | ||||
|         [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<IActionResult> UpdateTagTypeAsync([FromBody] UpdateTagTypeRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateTagTypeHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the TagType. | ||||
|         /// </summary> | ||||
|         [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<IActionResult> 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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<IValidator<GetFurnitureVariantsByIdsRequest>, GetFurnitureVariantsByIdsValidator>(); | ||||
|             #endregion | ||||
|  | ||||
|             #region TagType Services | ||||
|  | ||||
|             services.AddScoped<ITagTypePort, TagTypePort>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagTypesRequest>, TagTypeHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetTagTypeRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetAllTagTypesByListValidator>(); | ||||
|             services.AddScoped<IValidator<GetAllTagTypesByListRequest>, GetAllTagTypesByListValidator>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagTypesByListRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<CreateTagTypeValidator>(); | ||||
|             services.AddScoped<IValidator<CreateTagTypeRequest>, CreateTagTypeValidator>(); | ||||
|             services.AddScoped<IComponentHandler<CreateTagTypeRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<UpdateTagTypeValidator>(); | ||||
|             services.AddScoped<IValidator<UpdateTagTypeRequest>, UpdateTagTypeValidator>(); | ||||
|             services.AddScoped<IComponentHandler<UpdateTagTypeRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<ChangeTagTypeStatusValidator>(); | ||||
|             services.AddScoped<IValidator<ChangeTagTypeStatusRequest>, ChangeTagTypeStatusValidator>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeTagTypeStatusRequest>, TagTypeHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user