Compare commits
	
		
			2 Commits
		
	
	
		
			d922768c85
			...
			fc093e8bff
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| fc093e8bff | |||
|   | 6b0a681942 | 
							
								
								
									
										19
									
								
								Core.Inventory.Application/UseCases/Tag/Adapter/TagPort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Core.Inventory.Application/UseCases/Tag/Adapter/TagPort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.Tag.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Adapter | ||||
| { | ||||
|     public class TagPort : BasePresenter, ITagPort | ||||
|     { | ||||
|         public void Success(TagAdapter output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|         public void Success(List<TagAdapter> output) | ||||
|         { | ||||
|             ViewModel = new OkObjectResult(output); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class AddParentTagToTagRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string TagId { get; set; } | ||||
|         public string ParentTagId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using Core.Blueprint.Mongo; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class ChangeTagStatusRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public StatusEnum Status { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class CreateTagRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string TagName { get; set; } = null!; | ||||
|         public string TypeId { get; set; } = null!; | ||||
|         public string[] ParentTagId { get; set; } = null!; | ||||
|         public string Slug { get; set; } = null!; | ||||
|         public int DisplayOrder { get; set; } | ||||
|         public string Icon { get; set; } = null!; | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return TagName != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class GetAllTagsByListRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string[] Tags { get; set; } | ||||
|  | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Tags != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class GetAllTagsRequest : ICommand | ||||
|     { | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class GetTagRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class RemoveParentTagFromTagRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string TagId { get; set; } | ||||
|         public string ParentTagId { get; set; } | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Input | ||||
| { | ||||
|     public class UpdateTagRequest : Notificator, ICommand | ||||
|     { | ||||
|         public string Id { get; set; } = null!; | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string TagName { get; set; } = null!; | ||||
|         public string TypeId { get; set; } = null!; | ||||
|         public string[] ParentTagId { get; set; } = null!; | ||||
|         public string Slug { get; set; } = null!; | ||||
|         public int DisplayOrder { get; set; } | ||||
|         public string Icon { get; set; } = null!; | ||||
|         public bool Validate() | ||||
|         { | ||||
|             return Id != null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								Core.Inventory.Application/UseCases/Tag/Ports/ITagPort.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Core.Inventory.Application/UseCases/Tag/Ports/ITagPort.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Ports | ||||
| { | ||||
|     public interface ITagPort : IBasePort, | ||||
|         ICommandSuccessPort<TagAdapter>, | ||||
|         ICommandSuccessPort<List<TagAdapter>>, | ||||
|         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||
|         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||
|         IBadRequestPort | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										266
									
								
								Core.Inventory.Application/UseCases/Tag/TagHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										266
									
								
								Core.Inventory.Application/UseCases/Tag/TagHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,266 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using Core.Inventory.Application.UseCases.Tag.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.Tag | ||||
| { | ||||
|     public class TagHandler : | ||||
|         IComponentHandler<ChangeTagStatusRequest>, | ||||
|         IComponentHandler<GetAllTagsRequest>, | ||||
|         IComponentHandler<GetAllTagsByListRequest>, | ||||
|         IComponentHandler<UpdateTagRequest>, | ||||
|         IComponentHandler<GetTagRequest>, | ||||
|         IComponentHandler<CreateTagRequest>, | ||||
|         IComponentHandler<AddParentTagToTagRequest>, | ||||
|         IComponentHandler<RemoveParentTagFromTagRequest> | ||||
|     { | ||||
|         private readonly ITagPort _port; | ||||
|         private readonly IValidator<ChangeTagStatusRequest> _changeTagStatusValidator; | ||||
|         private readonly IValidator<CreateTagRequest> _registerTagValidator; | ||||
|         private readonly IValidator<UpdateTagRequest> _updateTagValidator; | ||||
|         private readonly IValidator<GetAllTagsByListRequest> _TagsByListValidator; | ||||
|         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||
|  | ||||
|         public TagHandler( | ||||
|             ITagPort port, | ||||
|             IValidator<ChangeTagStatusRequest> changeTagStatusValidator, | ||||
|             IValidator<CreateTagRequest> registerTagValidator, | ||||
|             IValidator<UpdateTagRequest> updateTagValidator, | ||||
|             IValidator<GetAllTagsByListRequest> TagsByListValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeTagStatusValidator = changeTagStatusValidator ?? throw new ArgumentNullException(nameof(changeTagStatusValidator)); | ||||
|             _registerTagValidator = registerTagValidator ?? throw new ArgumentNullException(nameof(registerTagValidator)); | ||||
|             _updateTagValidator = updateTagValidator ?? throw new ArgumentNullException(nameof(updateTagValidator)); | ||||
|             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||
|             _TagsByListValidator = TagsByListValidator ?? throw new ArgumentNullException(nameof(TagsByListValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTagRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.GetTagByIdAsync(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(GetAllTagsRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllTagsAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllTagsByListRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_TagsByListValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllTagsByListAsync(command.Tags, cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeTagStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeTagStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.ChangeStatusTagAsync(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(CreateTagRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerTagValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new TagRequest | ||||
|                 { | ||||
|                     TenantId = command.TenantId, | ||||
|                     TagName = command.TagName, | ||||
|                     TypeId = command.TypeId, | ||||
|                     ParentTagId = command.ParentTagId, | ||||
|                     Slug = command.Slug, | ||||
|                     DisplayOrder = command.DisplayOrder, | ||||
|                     Icon = command.Icon, | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.CreateTagAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateTagRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateTagValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new TagAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     TenantId = command.TenantId, | ||||
|                     TagName = command.TagName, | ||||
|                     TypeId = command.TypeId, | ||||
|                     ParentTagId = command.ParentTagId, | ||||
|                     Slug = command.Slug, | ||||
|                     DisplayOrder = command.DisplayOrder, | ||||
|                     Icon = command.Icon | ||||
|                 }; | ||||
|  | ||||
|                 string id = command.Id; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.UpdateTagAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(AddParentTagToTagRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.AddParentTagAsync(command.TagId, command.ParentTagId, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(RemoveParentTagFromTagRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.RemoveParentTagAsync(command.TagId, command.ParentTagId, 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.Tag.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Validator | ||||
| { | ||||
|     public class ChangeTagStatusValidator : AbstractValidator<ChangeTagStatusRequest> | ||||
|     { | ||||
|         public ChangeTagStatusValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Tag ID").WithMessage("Tag 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.Tag.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Validator | ||||
| { | ||||
|     public class CreateTagValidator : AbstractValidator<CreateTagRequest> | ||||
|     { | ||||
|         public CreateTagValidator() | ||||
|         { | ||||
|             RuleFor(i => i.TagName).NotEmpty().NotNull().OverridePropertyName(x => x.TagName).WithName("Tag Name").WithMessage("Tag Name is Obligatory."); | ||||
|             RuleFor(i => i.TypeId).NotEmpty().NotNull().OverridePropertyName(x => x.TypeId).WithName("Tag TypeId").WithMessage("Tag TypeId is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Validator | ||||
| { | ||||
|     public class GetAllTagsByListValidator : AbstractValidator<GetAllTagsByListRequest> | ||||
|     { | ||||
|         public GetAllTagsByListValidator() | ||||
|         { | ||||
|             RuleFor(i => i.Tags).NotEmpty().NotNull().OverridePropertyName(x => x.Tags).WithName("Tags").WithMessage("Tags are Obligatory."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.Tag.Validator | ||||
| { | ||||
|     public class UpdateTagValidator : AbstractValidator<UpdateTagRequest> | ||||
|     { | ||||
|         public UpdateTagValidator() | ||||
|         { | ||||
|             RuleFor(i => i.TagName).NotEmpty().NotNull().OverridePropertyName(x => x.TagName).WithName("Tag Name").WithMessage("Tag Name is Obligatory."); | ||||
|             RuleFor(i => i.TypeId).NotEmpty().NotNull().OverridePropertyName(x => x.TypeId).WithName("Tag TypeId").WithMessage("Tag TypeId is Obligatory."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -73,5 +73,33 @@ namespace Core.Inventory.External.Clients | ||||
|         Task<TagTypeAdapter> ChangeStatusTagTypeAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|  | ||||
|         #region Tag | ||||
|  | ||||
|         [Get("/api/v1/Tag")] | ||||
|         Task<IEnumerable<TagAdapter>> GetAllTagsAsync(CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/Tag/GetTagList")] | ||||
|         Task<IEnumerable<TagAdapter>> GetAllTagsByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Get("/api/v1/Tag/{id}")] | ||||
|         Task<TagAdapter> GetTagByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/Tag")] | ||||
|         Task<TagAdapter> CreateTagAsync([FromBody] TagRequest newTag, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Put("/api/v1/Tag/{id}")] | ||||
|         Task<TagAdapter> UpdateTagAsync([FromBody] TagAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Patch("/api/v1/Tag/{id}/{newStatus}/ChangeStatus")] | ||||
|         Task<TagAdapter> ChangeStatusTagAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Post("/api/v1/Tag/{tagId}/ParentTags/{parentTagId}/Add")] | ||||
|         Task<TagAdapter> AddParentTagAsync([FromRoute] string tagId, [FromRoute] string parentTagId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         [Delete("/api/v1/Tag/{tagId}/ParentTags/{parentTagId}/Remove")] | ||||
|         Task<TagAdapter> RemoveParentTagAsync([FromRoute] string tagId, [FromRoute] string parentTagId, CancellationToken cancellationToken = default); | ||||
|  | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										13
									
								
								Core.Inventory.External/Clients/Requests/TagRequest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Core.Inventory.External/Clients/Requests/TagRequest.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| namespace Core.Inventory.External.Clients.Requests | ||||
| { | ||||
|     public class TagRequest | ||||
|     { | ||||
|         public string TenantId { get; set; } = null!; | ||||
|         public string TagName { get; set; } = null!; | ||||
|         public string TypeId { get; set; } = null!; | ||||
|         public string[] ParentTagId { get; set; } = null!; | ||||
|         public string Slug { get; set; } = null!; | ||||
|         public int DisplayOrder { get; set; } | ||||
|         public string Icon { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
| @@ -7,7 +7,7 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Adapters.Lib" Version="1.0.9" /> | ||||
|     <PackageReference Include="Adapters.Lib" Version="1.0.10" /> | ||||
|     <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> | ||||
|     <PackageReference Include="Refit" Version="8.0.0" /> | ||||
|   </ItemGroup> | ||||
|   | ||||
							
								
								
									
										239
									
								
								Core.Inventory.Service.API/Controllers/TagController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										239
									
								
								Core.Inventory.Service.API/Controllers/TagController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,239 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using Core.Inventory.Application.UseCases.Tag.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="TagController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [AllowAnonymous] | ||||
|     public class TagController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetTagRequest> getTagHandler; | ||||
|         private readonly IComponentHandler<GetAllTagsRequest> getAllTagsHandler; | ||||
|         private readonly IComponentHandler<GetAllTagsByListRequest> getAllTagsByListHandler; | ||||
|         private readonly IComponentHandler<CreateTagRequest> createTagHandler; | ||||
|         private readonly IComponentHandler<UpdateTagRequest> updateTagHandler; | ||||
|         private readonly IComponentHandler<ChangeTagStatusRequest> changeTagStatusHandler; | ||||
|         private readonly IComponentHandler<AddParentTagToTagRequest> addParentTagToTagHandler; | ||||
|         private readonly IComponentHandler<RemoveParentTagFromTagRequest> removeParentTagFromTagUserHandler; | ||||
|         private readonly ITagPort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="TagController"/>. | ||||
|         /// </summary> | ||||
|         public TagController( | ||||
|             IComponentHandler<GetTagRequest> getTagHandler, | ||||
|             IComponentHandler<GetAllTagsRequest> getAllTagsHandler, | ||||
|             IComponentHandler<GetAllTagsByListRequest> getAllTagsByListHandler, | ||||
|             IComponentHandler<CreateTagRequest> createTagHandler, | ||||
|             IComponentHandler<UpdateTagRequest> updateTagHandler, | ||||
|             IComponentHandler<ChangeTagStatusRequest> changeTagStatusHandler, | ||||
|             IComponentHandler<AddParentTagToTagRequest> addParentTagToTagHandler, | ||||
|             IComponentHandler<RemoveParentTagFromTagRequest> removeParentTagFromTagUserHandler, | ||||
|             ITagPort port | ||||
|             ) | ||||
|         { | ||||
|             this.createTagHandler = createTagHandler; | ||||
|             this.updateTagHandler = updateTagHandler; | ||||
|             this.changeTagStatusHandler = changeTagStatusHandler; | ||||
|             this.getAllTagsHandler = getAllTagsHandler; | ||||
|             this.getTagHandler = getTagHandler; | ||||
|             this.getAllTagsByListHandler = getAllTagsByListHandler; | ||||
|             this.addParentTagToTagHandler = addParentTagToTagHandler; | ||||
|             this.removeParentTagFromTagUserHandler = removeParentTagFromTagUserHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the Tags. | ||||
|         /// </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> GetAllTagsAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllTagsHandler.ExecuteAsync(new GetAllTagsRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the Tags by Tag identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of Tag 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 Tags found.</response> | ||||
|         /// <response code="204">No content if no Tags are found.</response> | ||||
|         /// <response code="400">Bad request if the Tag 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("GetTagList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<TagAdapter>), 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> GetAllTagsByListAsync([FromBody] GetAllTagsByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request == null || request.Tags == null || !request.Tags.Any()) | ||||
|             { | ||||
|                 return BadRequest("Tag identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             await getAllTagsByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the Tag 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> GetTagById([FromBody] GetTagRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request.Id == null || !request.Id.Any()) | ||||
|             { | ||||
|                 return BadRequest("Invalid Tag Id"); | ||||
|             } | ||||
|  | ||||
|             await getTagHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new Tag. | ||||
|         /// </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> CreateTagAsync([FromBody] CreateTagRequest newTag, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createTagHandler.ExecuteAsync(newTag, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full Tag 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> UpdateTagAsync([FromBody] UpdateTagRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateTagHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the Tag. | ||||
|         /// </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> ChangeTagStatusAsync([FromBody] ChangeTagStatusRequest request, | ||||
|                                                                      CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid Tag identifier"); } | ||||
|  | ||||
|             await changeTagStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds a parentTag to the tag. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("AddParentTag")] | ||||
|         [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> AddParentTagAsync([FromBody] AddParentTagToTagRequest request, | ||||
|                                                                CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.TagId)) { return BadRequest("Invalid tag identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.ParentTagId)) { return BadRequest("Invalid parentTag identifier"); } | ||||
|              | ||||
|             await addParentTagToTagHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Remove a parentTag to the tag. | ||||
|         /// </summary> | ||||
|         [HttpDelete] | ||||
|         [Route("RemoveParentTag")] | ||||
|         [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> RemoveParentTagAsync([FromBody] RemoveParentTagFromTagRequest request, | ||||
|                                                                    CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.TagId)) { return BadRequest("Invalid tag identifier"); } | ||||
|             if (string.IsNullOrEmpty(request.ParentTagId)) { return BadRequest("Invalid parentTag identifier"); } | ||||
|              | ||||
|             await removeParentTagFromTagUserHandler.ExecuteAsync(request, cancellationToken); | ||||
|  | ||||
|             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.Tag; | ||||
| 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.TagType; | ||||
| using Core.Inventory.Application.UseCases.TagType.Adapter; | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| @@ -95,6 +100,33 @@ namespace Core.Inventory.Service.API.Extensions | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             #region Tag Services | ||||
|  | ||||
|             services.AddScoped<ITagPort, TagPort>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagsRequest>, TagHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetTagRequest>, TagHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetAllTagsByListValidator>(); | ||||
|             services.AddScoped<IValidator<GetAllTagsByListRequest>, GetAllTagsByListValidator>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagsByListRequest>, TagHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<CreateTagValidator>(); | ||||
|             services.AddScoped<IValidator<CreateTagRequest>, CreateTagValidator>(); | ||||
|             services.AddScoped<IComponentHandler<CreateTagRequest>, TagHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<UpdateTagValidator>(); | ||||
|             services.AddScoped<IValidator<UpdateTagRequest>, UpdateTagValidator>(); | ||||
|             services.AddScoped<IComponentHandler<UpdateTagRequest>, TagHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<ChangeTagStatusValidator>(); | ||||
|             services.AddScoped<IValidator<ChangeTagStatusRequest>, ChangeTagStatusValidator>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeTagStatusRequest>, TagHandler>(); | ||||
|  | ||||
|             services.AddScoped<IComponentHandler<AddParentTagToTagRequest>, TagHandler>(); | ||||
|             services.AddScoped<IComponentHandler<RemoveParentTagFromTagRequest>, TagHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user