Compare commits
	
		
			18 Commits
		
	
	
		
			main
			...
			c1df5e354b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c1df5e354b | |||
|   | 27d1bb680b | ||
| 4fa4693bb9 | |||
| 6d044e5de7 | |||
| 34ada90a28 | |||
| b529d905b1 | |||
|   | 85e186396d | ||
| a63a351b84 | |||
| ab3863943d | |||
| c446fa652e | |||
| fc093e8bff | |||
|   | 6b0a681942 | ||
| d922768c85 | |||
|   | e6d68f4fd3 | ||
| 542df8a203 | |||
| 0038169f5a | |||
| 24f647f90e | |||
| f76e318f92 | 
| @@ -7,19 +7,19 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Command to change the status of a furniture base model. |     /// Command to change the status of a furniture base model. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public class ChangeFurnitureBaseStatusRequest : Notificator, ICommand |     public class ChangeFurnitureBaseStatusRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
|         public string Id { get; set; } = null!; |         public string MongoId { get; set; } = null!; | ||||||
|         public StatusEnum Status { get; set; } |         public StatusEnum Status { get; set; } | ||||||
| 
 | 
 | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
|             return !string.IsNullOrWhiteSpace(Id); |             return !string.IsNullOrWhiteSpace(MongoId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -6,7 +6,7 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input.Common; | using Core.Inventory.Application.UseCases.Inventory.Input.Common; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Command for creating a new furniture base entity. |     /// Command for creating a new furniture base entity. | ||||||
| @@ -5,7 +5,7 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||||
| { | { | ||||||
|     public class GetAllFurnitureBaseRequest : ICommand |     public class GetAllFurnitureBaseRequest : ICommand | ||||||
|     { |     { | ||||||
| @@ -5,18 +5,18 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Query to retrieve a furniture base by its identifier. |     /// Query to retrieve a furniture base by its identifier. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public class GetFurnitureBaseByIdRequest : Notificator, ICommand |     public class GetFurnitureBaseByIdRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
|         public string Id { get; set; } = null!; |         public string MongoId { get; set; } = null!; | ||||||
| 
 | 
 | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
|             return !string.IsNullOrWhiteSpace(Id); |             return !string.IsNullOrWhiteSpace(MongoId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -6,13 +6,14 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input.Common; | using Core.Inventory.Application.UseCases.Inventory.Input.Common; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Base | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Command for updating an existing furniture base entity. |     /// Command for updating an existing furniture base entity. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public class UpdateFurnitureBaseRequest : Notificator, ICommand |     public class UpdateFurnitureBaseRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
|  |         public string _Id { get; set; } = null!; | ||||||
|         public string Id { get; set; } = null!; |         public string Id { get; set; } = null!; | ||||||
|         public string ModelName { get; set; } = null!; |         public string ModelName { get; set; } = null!; | ||||||
|         public string Material { get; set; } = null!; |         public string Material { get; set; } = null!; | ||||||
| @@ -26,7 +27,8 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input | |||||||
|         public List<string>? VariantIds { get; set; } |         public List<string>? VariantIds { get; set; } | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
|             return !string.IsNullOrWhiteSpace(Id) |             return !string.IsNullOrWhiteSpace(_Id) | ||||||
|  |                 && !string.IsNullOrWhiteSpace(Id) | ||||||
|                 && !string.IsNullOrWhiteSpace(ModelName) |                 && !string.IsNullOrWhiteSpace(ModelName) | ||||||
|                 && !string.IsNullOrWhiteSpace(Material) |                 && !string.IsNullOrWhiteSpace(Material) | ||||||
|                 && !string.IsNullOrWhiteSpace(Condition); |                 && !string.IsNullOrWhiteSpace(Condition); | ||||||
| @@ -6,19 +6,19 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Command to change the status of a furniture variant. |     /// Command to change the status of a furniture variant. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public class ChangeFurnitureVariantStatusRequest : Notificator, ICommand |     public class ChangeFurnitureVariantStatusRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
|         public string Id { get; set; } = null!; |         public string MongoId { get; set; } = null!; | ||||||
|         public StatusEnum Status { get; set; } |         public StatusEnum Status { get; set; } | ||||||
| 
 | 
 | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
|             return !string.IsNullOrWhiteSpace(Id); |             return !string.IsNullOrWhiteSpace(MongoId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -5,7 +5,7 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
| { | { | ||||||
|     public class CreateFurnitureVariantRequest : Notificator, ICommand |     public class CreateFurnitureVariantRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
| @@ -18,10 +18,10 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input | |||||||
|         public string Currency { get; set; } = "USD"; |         public string Currency { get; set; } = "USD"; | ||||||
|         public int Stock { get; set; } |         public int Stock { get; set; } | ||||||
| 
 | 
 | ||||||
|         public Guid CategoryId { get; set; } |         public string CategoryId { get; set; } = string.Empty; | ||||||
|         public Guid ProviderId { get; set; } |         public string ProviderId { get; set; } = string.Empty; | ||||||
| 
 | 
 | ||||||
|         public Dictionary<string, object> Attributes { get; set; } = []; |         public Dictionary<string, string> Attributes { get; set; } = []; | ||||||
| 
 | 
 | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
| @@ -29,9 +29,7 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input | |||||||
|                 && !string.IsNullOrWhiteSpace(Name) |                 && !string.IsNullOrWhiteSpace(Name) | ||||||
|                 && !string.IsNullOrWhiteSpace(Color) |                 && !string.IsNullOrWhiteSpace(Color) | ||||||
|                 && Price >= 0 |                 && Price >= 0 | ||||||
|                 && Stock >= 0 |                 && Stock >= 0; | ||||||
|                 && CategoryId != Guid.Empty |  | ||||||
|                 && ProviderId != Guid.Empty; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="GetAllFurnitureVariantRequest.cs"> | ||||||
|  | //     Core.Inventory | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
|  | { | ||||||
|  |     public class GetAllFurnitureVariantRequest : ICommand | ||||||
|  |     { | ||||||
|  |         public bool Validate() => true; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -5,7 +5,7 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
| { | { | ||||||
|     public class GetAllFurnitureVariantsByModelIdRequest : Notificator, ICommand |     public class GetAllFurnitureVariantsByModelIdRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
| @@ -5,15 +5,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
| { | { | ||||||
|     public class GetFurnitureVariantByIdRequest : Notificator, ICommand |     public class GetFurnitureVariantByIdRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
|         public string Id { get; set; } = null!; |         public string MongoId { get; set; } = null!; | ||||||
| 
 | 
 | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
|             return !string.IsNullOrWhiteSpace(Id); |             return !string.IsNullOrWhiteSpace(MongoId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -0,0 +1,22 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="GetVariantsByIdsRequest.cs"> | ||||||
|  | //     Core.Inventory | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Request to retrieve multiple furniture variants by their identifiers. | ||||||
|  |     /// </summary> | ||||||
|  |     public class GetFurnitureVariantsByIdsRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string[] Ids { get; set; } = []; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Ids is not null && Ids.Length > 0 && Ids.All(id => !string.IsNullOrWhiteSpace(id)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -6,13 +6,14 @@ | |||||||
| 
 | 
 | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Input | namespace Core.Inventory.Application.UseCases.Inventory.Input.Variant | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Command for updating an existing furniture variant. |     /// Command for updating an existing furniture variant. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     public class UpdateFurnitureVariantRequest : Notificator, ICommand |     public class UpdateFurnitureVariantRequest : Notificator, ICommand | ||||||
|     { |     { | ||||||
|  |         public string _Id { get; set; } = null!; | ||||||
|         public string Id { get; set; } = null!; |         public string Id { get; set; } = null!; | ||||||
|         public string ModelId { get; set; } = null!; |         public string ModelId { get; set; } = null!; | ||||||
|         public string Name { get; set; } = null!; |         public string Name { get; set; } = null!; | ||||||
| @@ -23,14 +24,15 @@ namespace Core.Inventory.Application.UseCases.Inventory.Input | |||||||
|         public decimal Price { get; set; } |         public decimal Price { get; set; } | ||||||
|         public string Currency { get; set; } = "USD"; |         public string Currency { get; set; } = "USD"; | ||||||
| 
 | 
 | ||||||
|         public Guid CategoryId { get; set; } |         public string CategoryId { get; set; } = string.Empty!; | ||||||
|         public Guid ProviderId { get; set; } |         public string ProviderId { get; set; } = string.Empty!; | ||||||
| 
 | 
 | ||||||
|         public Dictionary<string, object> Attributes { get; set; } = []; |         public Dictionary<string, string> Attributes { get; set; } = []; | ||||||
| 
 | 
 | ||||||
|         public bool Validate() |         public bool Validate() | ||||||
|         { |         { | ||||||
|             return !string.IsNullOrWhiteSpace(Id) && |             return !string.IsNullOrWhiteSpace(_Id) && | ||||||
|  |                    !string.IsNullOrWhiteSpace(Id) && | ||||||
|                    !string.IsNullOrWhiteSpace(ModelId) && |                    !string.IsNullOrWhiteSpace(ModelId) && | ||||||
|                    !string.IsNullOrWhiteSpace(Name) && |                    !string.IsNullOrWhiteSpace(Name) && | ||||||
|                    !string.IsNullOrWhiteSpace(Color) && |                    !string.IsNullOrWhiteSpace(Color) && | ||||||
| @@ -1,6 +1,9 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Base; | ||||||
|  | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||||
|  | using Core.Inventory.Application.UseCases.Inventory.Validator.Variant; | ||||||
| using Core.Inventory.External.Clients; | using Core.Inventory.External.Clients; | ||||||
|  | using Core.Inventory.External.Clients.Adapters; | ||||||
| using Core.Inventory.External.Clients.Requests; | using Core.Inventory.External.Clients.Requests; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| @@ -20,7 +23,9 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|         IComponentHandler<UpdateFurnitureVariantRequest>, |         IComponentHandler<UpdateFurnitureVariantRequest>, | ||||||
|         IComponentHandler<GetFurnitureVariantByIdRequest>, |         IComponentHandler<GetFurnitureVariantByIdRequest>, | ||||||
|         IComponentHandler<GetAllFurnitureVariantsByModelIdRequest>, |         IComponentHandler<GetAllFurnitureVariantsByModelIdRequest>, | ||||||
|         IComponentHandler<ChangeFurnitureVariantStatusRequest> |         IComponentHandler<ChangeFurnitureVariantStatusRequest>, | ||||||
|  |         IComponentHandler<GetFurnitureVariantsByIdsRequest>, | ||||||
|  |         IComponentHandler<GetAllFurnitureVariantRequest> | ||||||
|     { |     { | ||||||
|         // FurnitureBase |         // FurnitureBase | ||||||
|         private readonly IFurnitureBasePort _basePort; |         private readonly IFurnitureBasePort _basePort; | ||||||
| @@ -112,8 +117,10 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 var request = new FurnitureBaseRequest |                 var request = new FurnitureBaseAdapter | ||||||
|                 { |                 { | ||||||
|  |                     _Id = command._Id, | ||||||
|  |                     Id = command.Id, | ||||||
|                     BaseDescription = command.BaseDescription, |                     BaseDescription = command.BaseDescription, | ||||||
|                     Condition = command.Condition, |                     Condition = command.Condition, | ||||||
|                     MaintenanceNotes = command.MaintenanceNotes, |                     MaintenanceNotes = command.MaintenanceNotes, | ||||||
| @@ -129,7 +136,7 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|  |  | ||||||
|                 var result = await _inventoryDALService.UpdateFurnitureBaseAsync(request, command.Id, cancellationToken); |                 var result = await _inventoryDALService.UpdateFurnitureBaseAsync(command.Id, request, cancellationToken); | ||||||
|                 _basePort.Success(result); |                 _basePort.Success(result); | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
| @@ -161,7 +168,7 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 ArgumentNullException.ThrowIfNull(command); |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|                 var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.Id, cancellationToken); |                 var result = await _inventoryDALService.GetFurnitureBaseByIdAsync(command.MongoId, cancellationToken); | ||||||
|                 if (result is null) |                 if (result is null) | ||||||
|                 { |                 { | ||||||
|                     _basePort.NoContentSuccess(); |                     _basePort.NoContentSuccess(); | ||||||
| @@ -186,7 +193,7 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.Id, command.Status, cancellationToken); |                 var result = await _inventoryDALService.ChangeFurnitureBaseStatusAsync(command.MongoId, command.Status, cancellationToken); | ||||||
|                 _basePort.Success(result); |                 _basePort.Success(result); | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
| @@ -240,8 +247,10 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|                     _variantPort.ValidationErrors(command.Notifications); |                     _variantPort.ValidationErrors(command.Notifications); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|                 var request = new FurnitureVariantRequest |                 var request = new FurnitureVariantAdapter | ||||||
|                 { |                 { | ||||||
|  |                     _Id = command._Id, | ||||||
|  |                     Id = command.Id, | ||||||
|                     Stock = command.Stock, |                     Stock = command.Stock, | ||||||
|                     Attributes= command.Attributes, |                     Attributes= command.Attributes, | ||||||
|                     CategoryId = command.CategoryId, |                     CategoryId = command.CategoryId, | ||||||
| @@ -253,7 +262,7 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|                     Price = command.Price, |                     Price = command.Price, | ||||||
|                     ProviderId = command.ProviderId |                     ProviderId = command.ProviderId | ||||||
|                 }; |                 }; | ||||||
|                 var result = await _inventoryDALService.UpdateFurnitureVariantAsync(request, command.Id, cancellationToken); |                 var result = await _inventoryDALService.UpdateFurnitureVariantAsync(command.Id, request, cancellationToken); | ||||||
|                 _variantPort.Success(result); |                 _variantPort.Success(result); | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
| @@ -267,7 +276,7 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 ArgumentNullException.ThrowIfNull(command); |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|                 var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.Id, cancellationToken); |                 var result = await _inventoryDALService.GetFurnitureVariantByIdAsync(command.MongoId, cancellationToken); | ||||||
|                 if (result is null) |                 if (result is null) | ||||||
|                 { |                 { | ||||||
|                     _variantPort.NoContentSuccess(); |                     _variantPort.NoContentSuccess(); | ||||||
| @@ -300,6 +309,34 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetFurnitureVariantsByIdsRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(new GetFurnitureVariantsByIdsValidator())) | ||||||
|  |                 { | ||||||
|  |                     _variantPort.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryDALService.GetFurnitureVariantsByIdsAsync([.. command.Ids], cancellationToken); | ||||||
|  |  | ||||||
|  |                 if (result is null || !result.Any()) | ||||||
|  |                 { | ||||||
|  |                     _variantPort.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _variantPort.Success([.. result]); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _variantPort); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         public async ValueTask ExecuteAsync(ChangeFurnitureVariantStatusRequest command, CancellationToken cancellationToken = default) |         public async ValueTask ExecuteAsync(ChangeFurnitureVariantStatusRequest command, CancellationToken cancellationToken = default) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
| @@ -310,7 +347,7 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|                     _variantPort.ValidationErrors(command.Notifications); |                     _variantPort.ValidationErrors(command.Notifications); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|                 var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.Id, command.Status, cancellationToken); |                 var result = await _inventoryDALService.ChangeFurnitureVariantStatusAsync(command.MongoId, command.Status, cancellationToken); | ||||||
|                 _variantPort.Success(result); |                 _variantPort.Success(result); | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
| @@ -319,6 +356,24 @@ namespace Core.Inventory.Application.UseCases.Inventory | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetAllFurnitureVariantRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 var result = await _inventoryDALService.GetAllFurnitureVariantAsync(cancellationToken); | ||||||
|  |                 if (!result.Any()) | ||||||
|  |                 { | ||||||
|  |                     _variantPort.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |                 _variantPort.Success([.. result]); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _basePort); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         #endregion |         #endregion | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,13 +1,13 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Base; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base | ||||||
| { | { | ||||||
|     public class ChangeFurnitureBaseStatusValidator : AbstractValidator<ChangeFurnitureBaseStatusRequest> |     public class ChangeFurnitureBaseStatusValidator : AbstractValidator<ChangeFurnitureBaseStatusRequest> | ||||||
|     { |     { | ||||||
|         public ChangeFurnitureBaseStatusValidator() |         public ChangeFurnitureBaseStatusValidator() | ||||||
|         { |         { | ||||||
|             RuleFor(x => x.Id) |             RuleFor(x => x.MongoId) | ||||||
|                 .NotEmpty().WithMessage("Id is required."); |                 .NotEmpty().WithMessage("Id is required."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.Status) |             RuleFor(x => x.Status) | ||||||
| @@ -3,11 +3,11 @@ | |||||||
| //     Core.Inventory | //     Core.Inventory | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Base; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Common; | using Core.Inventory.Application.UseCases.Inventory.Validator.Common; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base | ||||||
| { | { | ||||||
|     public class CreateFurnitureBaseValidator : AbstractValidator<CreateFurnitureBaseRequest> |     public class CreateFurnitureBaseValidator : AbstractValidator<CreateFurnitureBaseRequest> | ||||||
|     { |     { | ||||||
| @@ -1,13 +1,13 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Base; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base | ||||||
| { | { | ||||||
|     public class GetFurnitureBaseByIdValidator : AbstractValidator<GetFurnitureBaseByIdRequest> |     public class GetFurnitureBaseByIdValidator : AbstractValidator<GetFurnitureBaseByIdRequest> | ||||||
|     { |     { | ||||||
|         public GetFurnitureBaseByIdValidator() |         public GetFurnitureBaseByIdValidator() | ||||||
|         { |         { | ||||||
|             RuleFor(x => x.Id) |             RuleFor(x => x.MongoId) | ||||||
|                 .NotEmpty().WithMessage("Id is required."); |                 .NotEmpty().WithMessage("Id is required."); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -1,13 +1,19 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Base; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Common; | using Core.Inventory.Application.UseCases.Inventory.Validator.Common; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Base | ||||||
| { | { | ||||||
|     public class UpdateFurnitureBaseValidator : AbstractValidator<UpdateFurnitureBaseRequest> |     public class UpdateFurnitureBaseValidator : AbstractValidator<UpdateFurnitureBaseRequest> | ||||||
|     { |     { | ||||||
|         public UpdateFurnitureBaseValidator() |         public UpdateFurnitureBaseValidator() | ||||||
|         { |         { | ||||||
|  |             RuleFor(x => x._Id) | ||||||
|  |                 .NotEmpty().WithMessage("_Id is required."); | ||||||
|  | 
 | ||||||
|  |             RuleFor(x => x.Id) | ||||||
|  |                 .NotEmpty().WithMessage("Id is required."); | ||||||
|  | 
 | ||||||
|             RuleFor(x => x.ModelName) |             RuleFor(x => x.ModelName) | ||||||
|                .NotEmpty().WithMessage("Model name is required."); |                .NotEmpty().WithMessage("Model name is required."); | ||||||
| 
 | 
 | ||||||
| @@ -1,13 +1,13 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant | ||||||
| { | { | ||||||
|     public class ChangeFurnitureVariantStatusValidator : AbstractValidator<ChangeFurnitureVariantStatusRequest> |     public class ChangeFurnitureVariantStatusValidator : AbstractValidator<ChangeFurnitureVariantStatusRequest> | ||||||
|     { |     { | ||||||
|         public ChangeFurnitureVariantStatusValidator() |         public ChangeFurnitureVariantStatusValidator() | ||||||
|         { |         { | ||||||
|             RuleFor(x => x.Id) |             RuleFor(x => x.MongoId) | ||||||
|                 .NotEmpty().WithMessage("Id is required."); |                 .NotEmpty().WithMessage("Id is required."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.Status) |             RuleFor(x => x.Status) | ||||||
| @@ -1,7 +1,7 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant | ||||||
| { | { | ||||||
|     public class CreateFurnitureVariantValidator : AbstractValidator<CreateFurnitureVariantRequest> |     public class CreateFurnitureVariantValidator : AbstractValidator<CreateFurnitureVariantRequest> | ||||||
|     { |     { | ||||||
| @@ -23,10 +23,10 @@ namespace Core.Inventory.Application.UseCases.Inventory.Validator | |||||||
|                 .GreaterThanOrEqualTo(0).WithMessage("Stock must be a non-negative value."); |                 .GreaterThanOrEqualTo(0).WithMessage("Stock must be a non-negative value."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.CategoryId) |             RuleFor(x => x.CategoryId) | ||||||
|                 .NotEqual(Guid.Empty).WithMessage("CategoryId is required."); |                 .NotEmpty().WithMessage("CategoryId is required."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.ProviderId) |             RuleFor(x => x.ProviderId) | ||||||
|                 .NotEqual(Guid.Empty).WithMessage("ProviderId is required."); |                 .NotEmpty().WithMessage("ProviderId is required."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.Currency) |             RuleFor(x => x.Currency) | ||||||
|                 .NotEmpty().WithMessage("Currency is required."); |                 .NotEmpty().WithMessage("Currency is required."); | ||||||
| @@ -1,7 +1,7 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant | ||||||
| { | { | ||||||
|     public class GetAllFurnitureVariantsByModelIdValidator : AbstractValidator<GetAllFurnitureVariantsByModelIdRequest> |     public class GetAllFurnitureVariantsByModelIdValidator : AbstractValidator<GetAllFurnitureVariantsByModelIdRequest> | ||||||
|     { |     { | ||||||
| @@ -1,13 +1,13 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant | ||||||
| { | { | ||||||
|     public class GetFurnitureVariantByIdValidator : AbstractValidator<GetFurnitureVariantByIdRequest> |     public class GetFurnitureVariantByIdValidator : AbstractValidator<GetFurnitureVariantByIdRequest> | ||||||
|     { |     { | ||||||
|         public GetFurnitureVariantByIdValidator() |         public GetFurnitureVariantByIdValidator() | ||||||
|         { |         { | ||||||
|             RuleFor(x => x.Id) |             RuleFor(x => x.MongoId) | ||||||
|                 .NotEmpty().WithMessage("Id is required."); |                 .NotEmpty().WithMessage("Id is required."); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -0,0 +1,27 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="GetVariantsByIdsValidator.cs"> | ||||||
|  | //     Core.Inventory | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Validator for <see cref="GetFurnitureVariantsByIdsRequest"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class GetFurnitureVariantsByIdsValidator : AbstractValidator<GetFurnitureVariantsByIdsRequest> | ||||||
|  |     { | ||||||
|  |         public GetFurnitureVariantsByIdsValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(x => x.Ids) | ||||||
|  |                 .NotNull() | ||||||
|  |                 .WithMessage("The list of IDs must not be null.") | ||||||
|  |                 .Must(ids => ids.Length!=0) | ||||||
|  |                 .WithMessage("At least one ID must be provided.") | ||||||
|  |                 .Must(ids => ids.All(id => !string.IsNullOrWhiteSpace(id))) | ||||||
|  |                 .WithMessage("All IDs must be non-empty strings."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,12 +1,15 @@ | |||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| 
 | 
 | ||||||
| namespace Core.Inventory.Application.UseCases.Inventory.Validator | namespace Core.Inventory.Application.UseCases.Inventory.Validator.Variant | ||||||
| { | { | ||||||
|     public class UpdateFurnitureVariantValidator : AbstractValidator<UpdateFurnitureVariantRequest> |     public class UpdateFurnitureVariantValidator : AbstractValidator<UpdateFurnitureVariantRequest> | ||||||
|     { |     { | ||||||
|         public UpdateFurnitureVariantValidator() |         public UpdateFurnitureVariantValidator() | ||||||
|         { |         { | ||||||
|  |             RuleFor(x => x._Id) | ||||||
|  |                 .NotEmpty().WithMessage("_Id is required."); | ||||||
|  | 
 | ||||||
|             RuleFor(x => x.Id) |             RuleFor(x => x.Id) | ||||||
|                 .NotEmpty().WithMessage("Id is required."); |                 .NotEmpty().WithMessage("Id is required."); | ||||||
| 
 | 
 | ||||||
| @@ -29,10 +32,10 @@ namespace Core.Inventory.Application.UseCases.Inventory.Validator | |||||||
|                 .NotEmpty().WithMessage("Currency is required."); |                 .NotEmpty().WithMessage("Currency is required."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.CategoryId) |             RuleFor(x => x.CategoryId) | ||||||
|                 .NotEqual(Guid.Empty).WithMessage("CategoryId is required."); |                 .NotEmpty().WithMessage("CategoryId is required."); | ||||||
| 
 | 
 | ||||||
|             RuleFor(x => x.ProviderId) |             RuleFor(x => x.ProviderId) | ||||||
|                 .NotEqual(Guid.Empty).WithMessage("ProviderId is required."); |                 .NotEmpty().WithMessage("ProviderId is required."); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Adapter | ||||||
|  | { | ||||||
|  |     public class DeleteProductResponseAdapter | ||||||
|  |     { | ||||||
|  |         public bool Success { get; init; } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,23 @@ | |||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.Ports; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Adapter | ||||||
|  | { | ||||||
|  |     public class ProductPort : BasePresenter, IProductPort | ||||||
|  |     { | ||||||
|  |         public void Success(ProductAdapter output) | ||||||
|  |         { | ||||||
|  |             ViewModel = new OkObjectResult(output); | ||||||
|  |         } | ||||||
|  |         public void Success(List<ProductAdapter> output) | ||||||
|  |         { | ||||||
|  |             ViewModel = new OkObjectResult(output); | ||||||
|  |         } | ||||||
|  |         public void Success(DeleteProductResponseAdapter output) | ||||||
|  |         { | ||||||
|  |             ViewModel = new OkObjectResult(output); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class ChangeProductStatusRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |         public ProductStatus NewStatus { get; set; } | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,18 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class CreateProductRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string ProductName { get; set; } = null!; | ||||||
|  |         public string Description { get; set; } = null!; | ||||||
|  |         public string ProductStatus { get; set; } = null!; | ||||||
|  |         public List<string> TagIds { get; set; } = new List<string>(); | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return ProductName != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class DeleteProductRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class GetAllProductsByListRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string[] Products { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Products != null && Products.Any(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,12 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class GetAllProductsRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class GetProductRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,20 @@ | |||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Input | ||||||
|  | { | ||||||
|  |     public class UpdateProductRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string ProductName { get; set; } = null!; | ||||||
|  |         public string Description { get; set; } = null!; | ||||||
|  |         public string ProductStatus { get; set; } = null!; | ||||||
|  |         public List<string> TagIds { get; set; } = new List<string>(); | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null && ProductName != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.Adapter; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Ports | ||||||
|  | { | ||||||
|  |     public interface IProductPort : IBasePort, | ||||||
|  |         ICommandSuccessPort<ProductAdapter>, | ||||||
|  |         ICommandSuccessPort<List<ProductAdapter>>, | ||||||
|  |         ICommandSuccessPort<DeleteProductResponseAdapter>, | ||||||
|  |         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||||
|  |         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||||
|  |         IBadRequestPort | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | }  | ||||||
							
								
								
									
										247
									
								
								Core.Inventory.Application/UseCases/Product/ProductHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										247
									
								
								Core.Inventory.Application/UseCases/Product/ProductHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,247 @@ | |||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.Adapter; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.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.Product | ||||||
|  | { | ||||||
|  |     public class ProductHandler : | ||||||
|  |         IComponentHandler<ChangeProductStatusRequest>, | ||||||
|  |         IComponentHandler<GetAllProductsRequest>, | ||||||
|  |         IComponentHandler<GetAllProductsByListRequest>, | ||||||
|  |         IComponentHandler<UpdateProductRequest>, | ||||||
|  |         IComponentHandler<GetProductRequest>, | ||||||
|  |         IComponentHandler<CreateProductRequest>, | ||||||
|  |         IComponentHandler<DeleteProductRequest> | ||||||
|  |     { | ||||||
|  |         private readonly IProductPort _port; | ||||||
|  |         private readonly IValidator<ChangeProductStatusRequest> _changeProductStatusValidator; | ||||||
|  |         private readonly IValidator<CreateProductRequest> _registerProductValidator; | ||||||
|  |         private readonly IValidator<UpdateProductRequest> _updateProductValidator; | ||||||
|  |         private readonly IValidator<GetAllProductsByListRequest> _productsByListValidator; | ||||||
|  |         private readonly IValidator<DeleteProductRequest> _deleteProductValidator; | ||||||
|  |         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||||
|  |  | ||||||
|  |         public ProductHandler( | ||||||
|  |             IProductPort port, | ||||||
|  |             IValidator<ChangeProductStatusRequest> changeProductStatusValidator, | ||||||
|  |             IValidator<CreateProductRequest> registerProductValidator, | ||||||
|  |             IValidator<UpdateProductRequest> updateProductValidator, | ||||||
|  |             IValidator<GetAllProductsByListRequest> productsByListValidator, | ||||||
|  |             IValidator<DeleteProductRequest> deleteProductValidator, | ||||||
|  |             IInventoryServiceClient inventoryDALService) | ||||||
|  |         { | ||||||
|  |             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||||
|  |             _changeProductStatusValidator = changeProductStatusValidator ?? throw new ArgumentNullException(nameof(changeProductStatusValidator)); | ||||||
|  |             _registerProductValidator = registerProductValidator ?? throw new ArgumentNullException(nameof(registerProductValidator)); | ||||||
|  |             _updateProductValidator = updateProductValidator ?? throw new ArgumentNullException(nameof(updateProductValidator)); | ||||||
|  |             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||||
|  |             _productsByListValidator = productsByListValidator ?? throw new ArgumentNullException(nameof(productsByListValidator)); | ||||||
|  |             _deleteProductValidator = deleteProductValidator ?? throw new ArgumentNullException(nameof(deleteProductValidator)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetProductRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.GetProductByIdAsync(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(GetAllProductsRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 var _result = await _inventoryServiceClient.GetAllProductsAsync(cancellationToken).ConfigureAwait(false); | ||||||
|  |                 if (!_result.Any()) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |                 _port.Success(_result.ToList()); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetAllProductsByListRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_productsByListValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var _result = await _inventoryServiceClient.GetAllProductsByListAsync(command.Products, cancellationToken).ConfigureAwait(false); | ||||||
|  |                 if (!_result.Any()) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |                 _port.Success(_result.ToList()); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(ChangeProductStatusRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_changeProductStatusValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.ChangeProductStatusAsync(command.Id, command.NewStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (result == null) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(result); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(CreateProductRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_registerProductValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var productRequest = new ProductRequest | ||||||
|  |                 { | ||||||
|  |                     TenantId = command.TenantId, | ||||||
|  |                     ProductName = command.ProductName, | ||||||
|  |                     Description = command.Description, | ||||||
|  |                     ProductStatus = command.ProductStatus, | ||||||
|  |                     TagIds = command.TagIds | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.CreateProductAsync(productRequest, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (result == null) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(result); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(UpdateProductRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_updateProductValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var productAdapter = new ProductAdapter | ||||||
|  |                 { | ||||||
|  |                     Id = command.Id, | ||||||
|  |                     TenantId = command.TenantId, | ||||||
|  |                     ProductName = command.ProductName, | ||||||
|  |                     Description = command.Description, | ||||||
|  |                     ProductStatus = Enum.Parse<ProductStatus>(command.ProductStatus), | ||||||
|  |                     TagIds = command.TagIds.Select(id => MongoDB.Bson.ObjectId.Parse(id)).ToList() | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.UpdateProductAsync(productAdapter, 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(DeleteProductRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_deleteProductValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.DeleteProductAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (!result) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(new DeleteProductResponseAdapter() { Success = true }); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Validator | ||||||
|  | { | ||||||
|  |     public class ChangeProductStatusValidator : AbstractValidator<ChangeProductStatusRequest> | ||||||
|  |     { | ||||||
|  |         public ChangeProductStatusValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Product Id").WithMessage("Product Id is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Validator | ||||||
|  | { | ||||||
|  |     public class CreateProductValidator : AbstractValidator<CreateProductRequest> | ||||||
|  |     { | ||||||
|  |         public CreateProductValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.ProductName).NotEmpty().NotNull().OverridePropertyName(x => x.ProductName).WithName("Product Name").WithMessage("Product Name is Obligatory."); | ||||||
|  |             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Product Description").WithMessage("Product Description is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Validator | ||||||
|  | { | ||||||
|  |     public class DeleteProductValidator : AbstractValidator<DeleteProductRequest> | ||||||
|  |     { | ||||||
|  |         public DeleteProductValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Product Id").WithMessage("Product Id is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Validator | ||||||
|  | { | ||||||
|  |     public class GetAllProductsByListValidator : AbstractValidator<GetAllProductsByListRequest> | ||||||
|  |     { | ||||||
|  |         public GetAllProductsByListValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Products).NotEmpty().NotNull().OverridePropertyName(x => x.Products).WithName("Products").WithMessage("Products are Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Product.Validator | ||||||
|  | { | ||||||
|  |     public class UpdateProductValidator : AbstractValidator<UpdateProductRequest> | ||||||
|  |     { | ||||||
|  |         public UpdateProductValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.ProductName).NotEmpty().NotNull().OverridePropertyName(x => x.ProductName).WithName("Product Name").WithMessage("Product Name is Obligatory."); | ||||||
|  |             RuleFor(i => i.Description).NotEmpty().NotNull().OverridePropertyName(x => x.Description).WithName("Product Description").WithMessage("Product Description is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
							
								
								
									
										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 DeleteTagRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != 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 | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										298
									
								
								Core.Inventory.Application/UseCases/Tag/TagHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										298
									
								
								Core.Inventory.Application/UseCases/Tag/TagHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,298 @@ | |||||||
|  | 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>, | ||||||
|  |         IComponentHandler<DeleteTagRequest> | ||||||
|  |     { | ||||||
|  |         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; | ||||||
|  |         private readonly IValidator<DeleteTagRequest> _deleteTagValidator; | ||||||
|  |  | ||||||
|  |         public TagHandler( | ||||||
|  |             ITagPort port, | ||||||
|  |             IValidator<ChangeTagStatusRequest> changeTagStatusValidator, | ||||||
|  |             IValidator<CreateTagRequest> registerTagValidator, | ||||||
|  |             IValidator<UpdateTagRequest> updateTagValidator, | ||||||
|  |             IValidator<GetAllTagsByListRequest> TagsByListValidator, | ||||||
|  |             IValidator<DeleteTagRequest> deleteTagValidator, | ||||||
|  |             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)); | ||||||
|  |             _deleteTagValidator = deleteTagValidator ?? throw new ArgumentNullException(nameof(deleteTagValidator)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         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); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(DeleteTagRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_deleteTagValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.DeleteTagAsync(command.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.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,13 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.Tag.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.Tag.Validator | ||||||
|  | { | ||||||
|  |     public class DeleteTagValidator : AbstractValidator<DeleteTagRequest> | ||||||
|  |     { | ||||||
|  |         public DeleteTagValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("Tag Id").WithMessage("Tag Id 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."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Adapter | ||||||
|  | { | ||||||
|  |     public class TagOverridePort : BasePresenter, ITagOverridePort | ||||||
|  |     { | ||||||
|  |         public void Success(TagOverrideAdapter output) | ||||||
|  |         { | ||||||
|  |             ViewModel = new OkObjectResult(output); | ||||||
|  |         } | ||||||
|  |         public void Success(List<TagOverrideAdapter> output) | ||||||
|  |         { | ||||||
|  |             ViewModel = new OkObjectResult(output); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class ChangeTagOverrideStatusRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class CreateTagOverrideRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string BaseTagId { get; set; } = null!; | ||||||
|  |         public string OverrideTagId { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return BaseTagId != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class DeleteTagOverrideRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class GetAllTagOverridesByListRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string[] TagOverrides { get; set; } | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return TagOverrides != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,12 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class GetAllTagOverridesRequest : ICommand | ||||||
|  |     { | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class GetTagOverrideRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Input | ||||||
|  | { | ||||||
|  |     public class UpdateTagOverrideRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string BaseTagId { get; set; } = null!; | ||||||
|  |         public string OverrideTagId { get; set; } = null!; | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Ports | ||||||
|  | { | ||||||
|  |     public interface ITagOverridePort : IBasePort, | ||||||
|  |         ICommandSuccessPort<TagOverrideAdapter>, | ||||||
|  |         ICommandSuccessPort<List<TagOverrideAdapter>>, | ||||||
|  |         INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort, | ||||||
|  |         INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort, | ||||||
|  |         IBadRequestPort | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,244 @@ | |||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||||
|  | using Core.Inventory.External.Clients; | ||||||
|  | using Core.Inventory.External.Clients.Requests; | ||||||
|  | using FluentValidation; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Lib.Architecture.BuildingBlocks.Helpers; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride | ||||||
|  | { | ||||||
|  |     public class TagOverrideHandler : | ||||||
|  |         IComponentHandler<ChangeTagOverrideStatusRequest>, | ||||||
|  |         IComponentHandler<GetAllTagOverridesRequest>, | ||||||
|  |         IComponentHandler<GetAllTagOverridesByListRequest>, | ||||||
|  |         IComponentHandler<UpdateTagOverrideRequest>, | ||||||
|  |         IComponentHandler<GetTagOverrideRequest>, | ||||||
|  |         IComponentHandler<CreateTagOverrideRequest>, | ||||||
|  |         IComponentHandler<DeleteTagOverrideRequest> | ||||||
|  |     { | ||||||
|  |         private readonly ITagOverridePort _port; | ||||||
|  |         private readonly IValidator<ChangeTagOverrideStatusRequest> _changeTagOverrideStatusValidator; | ||||||
|  |         private readonly IValidator<CreateTagOverrideRequest> _registerTagOverrideValidator; | ||||||
|  |         private readonly IValidator<UpdateTagOverrideRequest> _updateTagOverrideValidator; | ||||||
|  |         private readonly IValidator<GetAllTagOverridesByListRequest> _TagOverridesByListValidator; | ||||||
|  |         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||||
|  |         private readonly IValidator<DeleteTagOverrideRequest> _deleteTagOverrideValidator; | ||||||
|  |  | ||||||
|  |         public TagOverrideHandler( | ||||||
|  |             ITagOverridePort port, | ||||||
|  |             IValidator<ChangeTagOverrideStatusRequest> changeTagOverrideStatusValidator, | ||||||
|  |             IValidator<CreateTagOverrideRequest> registerTagOverrideValidator, | ||||||
|  |             IValidator<UpdateTagOverrideRequest> updateTagOverrideValidator, | ||||||
|  |             IValidator<GetAllTagOverridesByListRequest> TagOverridesByListValidator, | ||||||
|  |             IValidator<DeleteTagOverrideRequest> deleteTagOverrideValidator, | ||||||
|  |             IInventoryServiceClient inventoryDALService) | ||||||
|  |         { | ||||||
|  |             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||||
|  |             _changeTagOverrideStatusValidator = changeTagOverrideStatusValidator ?? throw new ArgumentNullException(nameof(changeTagOverrideStatusValidator)); | ||||||
|  |             _registerTagOverrideValidator = registerTagOverrideValidator ?? throw new ArgumentNullException(nameof(registerTagOverrideValidator)); | ||||||
|  |             _updateTagOverrideValidator = updateTagOverrideValidator ?? throw new ArgumentNullException(nameof(updateTagOverrideValidator)); | ||||||
|  |             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||||
|  |             _TagOverridesByListValidator = TagOverridesByListValidator ?? throw new ArgumentNullException(nameof(TagOverridesByListValidator)); | ||||||
|  |             _deleteTagOverrideValidator = deleteTagOverrideValidator ?? throw new ArgumentNullException(nameof(deleteTagOverrideValidator)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.GetTagOverrideByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (result == null) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(result); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetAllTagOverridesRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 var _result = await _inventoryServiceClient.GetAllTagOverridesAsync().ConfigureAwait(false); | ||||||
|  |                 if (!_result.Any()) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |                 _port.Success(_result.ToList()); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(GetAllTagOverridesByListRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_TagOverridesByListValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var _result = await _inventoryServiceClient.GetAllTagOverridesByListAsync(command.TagOverrides, cancellationToken).ConfigureAwait(false); | ||||||
|  |                 if (!_result.Any()) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |                 _port.Success(_result.ToList()); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(ChangeTagOverrideStatusRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_changeTagOverrideStatusValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.ChangeStatusTagOverrideAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (result == null) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(result); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(CreateTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_registerTagOverrideValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var request = new TagOverrideRequest | ||||||
|  |                 { | ||||||
|  |                     TenantId = command.TenantId, | ||||||
|  |                     BaseTagId = command.BaseTagId, | ||||||
|  |                     OverrideTagId = command.OverrideTagId, | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.CreateTagOverrideAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (result == null) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(result); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(UpdateTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_updateTagOverrideValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var request = new TagOverrideAdapter | ||||||
|  |                 { | ||||||
|  |                     Id = command.Id, | ||||||
|  |                     TenantId = command.TenantId, | ||||||
|  |                     BaseTagId = command.BaseTagId, | ||||||
|  |                     OverrideTagId = command.OverrideTagId | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 string id = command.Id; | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.UpdateTagOverrideAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |                 if (result == null) | ||||||
|  |                 { | ||||||
|  |                     _port.NoContentSuccess(); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 _port.Success(result); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(DeleteTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_deleteTagOverrideValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.DeleteTagOverrideAsync(command.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.TagOverride.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||||
|  | { | ||||||
|  |     public class ChangeTagOverrideStatusValidator : AbstractValidator<ChangeTagOverrideStatusRequest> | ||||||
|  |     { | ||||||
|  |         public ChangeTagOverrideStatusValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagOverride ID").WithMessage("TagOverride ID is Obligatory."); | ||||||
|  |             RuleFor(i => i.Status).NotNull().OverridePropertyName(x => x.Status).WithName("Status").WithMessage("Status is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||||
|  | { | ||||||
|  |     public class CreateTagOverrideValidator : AbstractValidator<CreateTagOverrideRequest> | ||||||
|  |     { | ||||||
|  |         public CreateTagOverrideValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.BaseTagId).NotEmpty().NotNull().OverridePropertyName(x => x.BaseTagId).WithName("TagOverride BaseTagId").WithMessage("TagOverride BaseTagId is Obligatory."); | ||||||
|  |             RuleFor(i => i.OverrideTagId).NotEmpty().NotNull().OverridePropertyName(x => x.OverrideTagId).WithName("TagOverride OverrideTagId").WithMessage("TagOverride OverrideTagId is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||||
|  | { | ||||||
|  |     public class DeleteTagOverrideValidator : AbstractValidator<DeleteTagOverrideRequest> | ||||||
|  |     { | ||||||
|  |         public DeleteTagOverrideValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagOverride Id").WithMessage("TagOverride Id is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||||
|  | { | ||||||
|  |     public class GetAllTagOverridesByListValidator : AbstractValidator<GetAllTagOverridesByListRequest> | ||||||
|  |     { | ||||||
|  |         public GetAllTagOverridesByListValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.TagOverrides).NotEmpty().NotNull().OverridePropertyName(x => x.TagOverrides).WithName("TagOverrides").WithMessage("TagOverrides are Obligatory."); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagOverride.Validator | ||||||
|  | { | ||||||
|  |     public class UpdateTagOverrideValidator : AbstractValidator<UpdateTagOverrideRequest> | ||||||
|  |     { | ||||||
|  |         public UpdateTagOverrideValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.BaseTagId).NotEmpty().NotNull().OverridePropertyName(x => x.BaseTagId).WithName("TagOverride BaseTagId").WithMessage("TagOverride BaseTagId is Obligatory."); | ||||||
|  |             RuleFor(i => i.OverrideTagId).NotEmpty().NotNull().OverridePropertyName(x => x.OverrideTagId).WithName("TagOverride OverrideTagId").WithMessage("TagOverride OverrideTagId is Obligatory."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -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 DeleteTagTypeRequest : Notificator, ICommand | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         public bool Validate() | ||||||
|  |         { | ||||||
|  |             return Id != 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,17 @@ | |||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  |  | ||||||
|  | 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 | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										246
									
								
								Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										246
									
								
								Core.Inventory.Application/UseCases/TagType/TagTypeHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,246 @@ | |||||||
|  | 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>, | ||||||
|  |         IComponentHandler<DeleteTagTypeRequest> | ||||||
|  |     { | ||||||
|  |         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 IValidator<DeleteTagTypeRequest> _deleteTagTypeValidator; | ||||||
|  |         private readonly IInventoryServiceClient _inventoryServiceClient; | ||||||
|  |  | ||||||
|  |         public TagTypeHandler( | ||||||
|  |             ITagTypePort port, | ||||||
|  |             IValidator<ChangeTagTypeStatusRequest> changeTagTypeStatusValidator, | ||||||
|  |             IValidator<CreateTagTypeRequest> registerTagTypeValidator, | ||||||
|  |             IValidator<UpdateTagTypeRequest> updateTagTypeValidator, | ||||||
|  |             IValidator<GetAllTagTypesByListRequest> TagTypesByListValidator, | ||||||
|  |             IValidator<DeleteTagTypeRequest> deleteTagTypeValidator, | ||||||
|  |             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)); | ||||||
|  |             _deleteTagTypeValidator = deleteTagTypeValidator ?? throw new ArgumentNullException(nameof(deleteTagTypeValidator)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         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); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public async ValueTask ExecuteAsync(DeleteTagTypeRequest command, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 ArgumentNullException.ThrowIfNull(command); | ||||||
|  |  | ||||||
|  |                 if (!command.IsValid(_deleteTagTypeValidator)) | ||||||
|  |                 { | ||||||
|  |                     _port.ValidationErrors(command.Notifications); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var result = await _inventoryServiceClient.DeleteTagTypeAsync(command.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,13 @@ | |||||||
|  | using Core.Inventory.Application.UseCases.TagType.Input; | ||||||
|  | using FluentValidation; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Application.UseCases.TagType.Validator | ||||||
|  | { | ||||||
|  |     public class DeleteTagTypeValidator : AbstractValidator<DeleteTagTypeRequest> | ||||||
|  |     { | ||||||
|  |         public DeleteTagTypeValidator() | ||||||
|  |         { | ||||||
|  |             RuleFor(i => i.Id).NotEmpty().NotNull().OverridePropertyName(x => x.Id).WithName("TagType Id").WithMessage("TagType Id 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."); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | using Core.Adapters.Lib; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Adapters | ||||||
|  | { | ||||||
|  |     public class FurnitureBaseAdapter | ||||||
|  |     { | ||||||
|  |         public string _Id { get; set; } = null!; | ||||||
|  |         public string Id { get; init; } = null!; | ||||||
|  |         public string ModelName { get; set; } = null!; | ||||||
|  |         public string Material { get; set; } = null!; | ||||||
|  |         public string Condition { get; set; } = null!; | ||||||
|  |         public string? BaseDescription { get; set; } | ||||||
|  |         public string? Representation { get; set; } | ||||||
|  |         public string? MaintenanceNotes { get; set; } | ||||||
|  |  | ||||||
|  |         public Dimensions Dimensions { get; set; } = new(); | ||||||
|  |         public List<string>? VariantIds { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,21 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Adapters | ||||||
|  | { | ||||||
|  |     public class FurnitureVariantAdapter | ||||||
|  |     { | ||||||
|  |         public string _Id { get; set; } = null!; | ||||||
|  |         public string Id { get; init; } = null!; | ||||||
|  |         public string ModelId { get; set; } = null!; | ||||||
|  |         public string Name { get; set; } = null!; | ||||||
|  |         public string Color { get; set; } = null!; | ||||||
|  |         public string? Line { get; set; } | ||||||
|  |  | ||||||
|  |         public decimal Price { get; set; } | ||||||
|  |         public string Currency { get; set; } = "USD"; | ||||||
|  |         public int Stock { get; set; } | ||||||
|  |  | ||||||
|  |         public string CategoryId { get; set; } = string.Empty!; | ||||||
|  |         public string ProviderId { get; set; } = string.Empty!; | ||||||
|  |  | ||||||
|  |         public Dictionary<string, string> Attributes { get; set; } = []; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,5 +1,7 @@ | |||||||
| using Core.Adapters.Lib; | using Core.Adapters.Lib; | ||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Inventory.External.Clients.Adapters; | ||||||
| using Core.Inventory.External.Clients.Requests; | using Core.Inventory.External.Clients.Requests; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| using Refit; | using Refit; | ||||||
| @@ -13,36 +15,153 @@ namespace Core.Inventory.External.Clients | |||||||
|         [Get("/api/v1/FurnitureBase")] |         [Get("/api/v1/FurnitureBase")] | ||||||
|         Task<IEnumerable<FurnitureBase>> GetAllFurnitureBaseAsync(CancellationToken cancellationToken = default); |         Task<IEnumerable<FurnitureBase>> GetAllFurnitureBaseAsync(CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Get("/api/v1/FurnitureBase/{id}")] |         [Get("/api/v1/FurnitureBase/{mongoId}")] | ||||||
|         Task<FurnitureBase> GetFurnitureBaseByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); |         Task<FurnitureBase> GetFurnitureBaseByIdAsync([FromRoute] string mongoId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Post("/api/v1/FurnitureBase")] |         [Post("/api/v1/FurnitureBase")] | ||||||
|         Task<FurnitureBase> CreateFurnitureBaseAsync([FromBody] FurnitureBaseRequest request, CancellationToken cancellationToken = default); |         Task<FurnitureBase> CreateFurnitureBaseAsync([FromBody] FurnitureBaseRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Put("/api/v1/FurnitureBase/{id}")] |         [Put("/api/v1/FurnitureBase/{id}")] | ||||||
|         Task<FurnitureBase> UpdateFurnitureBaseAsync([FromBody] FurnitureBaseRequest request, [FromRoute] string id, CancellationToken cancellationToken = default); |         Task<FurnitureBase> UpdateFurnitureBaseAsync([FromRoute] string id, [FromBody] FurnitureBaseAdapter request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Patch("/api/v1/FurnitureBase/{id}/{newStatus}/ChangeStatus")] |         [Patch("/api/v1/FurnitureBase/{mongoId}/{newStatus}/ChangeStatus")] | ||||||
|         Task<FurnitureBase> ChangeFurnitureBaseStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); |         Task<FurnitureBase> ChangeFurnitureBaseStatusAsync([FromRoute] string mongoId, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         #endregion |         #endregion | ||||||
|  |  | ||||||
|         #region FurnitureVariant |         #region FurnitureVariant | ||||||
|  |  | ||||||
|         [Get("/api/v1/FurnitureVariant/{modelId}")] |         [Get("/api/v1/FurnitureVariant/ByModel/{modelId}")] | ||||||
|         Task<IEnumerable<FurnitureVariant>> GetAllVariantsByModelIdAsync([FromRoute] string modelId, CancellationToken cancellationToken = default); |         Task<IEnumerable<FurnitureVariant>> GetAllVariantsByModelIdAsync([FromRoute] string modelId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Get("/api/v1/FurnitureVariant/{id}/byId")] |         [Get("/api/v1/FurnitureVariant/{mongoId}")] | ||||||
|         Task<FurnitureVariant> GetFurnitureVariantByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); |         Task<FurnitureVariant> GetFurnitureVariantByIdAsync([FromRoute] string mongoId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureVariant/ByIds")] | ||||||
|  |         Task<IEnumerable<FurnitureVariant>> GetFurnitureVariantsByIdsAsync([Body] string[] ids, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Post("/api/v1/FurnitureVariant")] |         [Post("/api/v1/FurnitureVariant")] | ||||||
|         Task<FurnitureVariant> CreateFurnitureVariantAsync([FromBody] FurnitureVariantRequest request, CancellationToken cancellationToken = default); |         Task<FurnitureVariant> CreateFurnitureVariantAsync([FromBody] FurnitureVariantRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Put("/api/v1/FurnitureVariant/{id}")] |         [Put("/api/v1/FurnitureVariant/{id}")] | ||||||
|         Task<FurnitureVariant> UpdateFurnitureVariantAsync([FromBody] FurnitureVariantRequest request, [FromRoute] string id, CancellationToken cancellationToken = default); |         Task<FurnitureVariant> UpdateFurnitureVariantAsync([FromRoute] string id, [FromBody] FurnitureVariantAdapter request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         [Patch("/api/v1/FurnitureVariant/{id}/{newStatus}/ChangeStatus")] |         [Patch("/api/v1/FurnitureVariant/{mongoId}/{newStatus}/ChangeStatus")] | ||||||
|         Task<FurnitureVariant> ChangeFurnitureVariantStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); |         Task<FurnitureVariant> ChangeFurnitureVariantStatusAsync([FromRoute] string mongoId, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [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); | ||||||
|  |  | ||||||
|  |         [Delete("/api/v1/TagType/{id}")] | ||||||
|  |         Task<TagTypeAdapter> DeleteTagTypeAsync([FromRoute] string id, 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); | ||||||
|  |  | ||||||
|  |         [Delete("/api/v1/Tag/{id}")] | ||||||
|  |         Task<TagAdapter> DeleteTagAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         #endregion | ||||||
|  |  | ||||||
|  |         #region TagOverride | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/TagOverride")] | ||||||
|  |         Task<IEnumerable<TagOverrideAdapter>> GetAllTagOverridesAsync(CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/TagOverride/GetTagOverrideList")] | ||||||
|  |         Task<IEnumerable<TagOverrideAdapter>> GetAllTagOverridesByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/TagOverride/{id}")] | ||||||
|  |         Task<TagOverrideAdapter> GetTagOverrideByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/TagOverride")] | ||||||
|  |         Task<TagOverrideAdapter> CreateTagOverrideAsync([FromBody] TagOverrideRequest newTagOverride, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Put("/api/v1/TagOverride/{id}")] | ||||||
|  |         Task<TagOverrideAdapter> UpdateTagOverrideAsync([FromBody] TagOverrideAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Patch("/api/v1/TagOverride/{id}/{newStatus}/ChangeStatus")] | ||||||
|  |         Task<TagOverrideAdapter> ChangeStatusTagOverrideAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Delete("/api/v1/TagOverride/{id}")] | ||||||
|  |         Task<TagOverrideAdapter> DeleteTagOverrideAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         #endregion | ||||||
|  |  | ||||||
|  |         #region Product | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/Product")] | ||||||
|  |         Task<IEnumerable<ProductAdapter>> GetAllProductsAsync(CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Product/GetProductList")] | ||||||
|  |         Task<IEnumerable<ProductAdapter>> GetAllProductsByListAsync([FromBody] string[] request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/Product/{id}")] | ||||||
|  |         Task<ProductAdapter> GetProductByIdAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Product")] | ||||||
|  |         Task<ProductAdapter> CreateProductAsync([FromBody] ProductRequest newProduct, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Put("/api/v1/Product/{id}")] | ||||||
|  |         Task<ProductAdapter> UpdateProductAsync([FromBody] ProductAdapter entity, [FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Patch("/api/v1/Product/{id}/{newStatus}/ChangeStatus")] | ||||||
|  |         Task<ProductAdapter> ChangeProductStatusAsync([FromRoute] string id, [FromRoute] ProductStatus newStatus, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Product/{productId}/tags/{tagId}")] | ||||||
|  |         Task<ProductAdapter> AddTagToProductAsync([FromRoute] string productId, [FromRoute] string tagId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Delete("/api/v1/Product/{productId}/tags/{tagId}")] | ||||||
|  |         Task<ProductAdapter> RemoveTagFromProductAsync([FromRoute] string productId, [FromRoute] string tagId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Delete("/api/v1/Product/{id}")] | ||||||
|  |         Task<bool> DeleteProductAsync([FromRoute] string id, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|         #endregion |         #endregion | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -11,9 +11,9 @@ | |||||||
|         public string Currency { get; set; } = "USD"; |         public string Currency { get; set; } = "USD"; | ||||||
|         public int Stock { get; set; } |         public int Stock { get; set; } | ||||||
|  |  | ||||||
|         public Guid CategoryId { get; set; } |         public string CategoryId { get; set; } = string.Empty!; | ||||||
|         public Guid ProviderId { get; set; } |         public string ProviderId { get; set; } = string.Empty!; | ||||||
|  |  | ||||||
|         public Dictionary<string, object> Attributes { get; set; } = []; |         public Dictionary<string, string> Attributes { get; set; } = []; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								Core.Inventory.External/Clients/Requests/ProductRequest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Core.Inventory.External/Clients/Requests/ProductRequest.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Requests | ||||||
|  | { | ||||||
|  |     public class ProductRequest | ||||||
|  |     { | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string ProductName { get; set; } = null!; | ||||||
|  |         public string Description { get; set; } = null!; | ||||||
|  |         public string ProductStatus { get; set; } = null!; | ||||||
|  |         public List<string> TagIds { get; set; } = new List<string>(); | ||||||
|  |     } | ||||||
|  | }  | ||||||
| @@ -0,0 +1,9 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Requests | ||||||
|  | { | ||||||
|  |     public class TagOverrideRequest | ||||||
|  |     { | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string BaseTagId { get; set; } = null!; | ||||||
|  |         public string OverrideTagId { get; set; } = null!; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										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!; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										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> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Adapters.Lib" Version="1.0.3" /> |     <PackageReference Include="Adapters.Lib" Version="1.0.13" /> | ||||||
|     <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> |     <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> | ||||||
|     <PackageReference Include="Refit" Version="8.0.0" /> |     <PackageReference Include="Refit" Version="8.0.0" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Base; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| @@ -10,30 +10,20 @@ namespace Core.Inventory.Service.API.Controllers | |||||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|     [Produces("application/json")] |     [Produces("application/json")] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     public class FurnitureBaseController : ControllerBase |     public class FurnitureBaseController( | ||||||
|  |         IComponentHandler<GetFurnitureBaseByIdRequest> getByIdHandler, | ||||||
|  |         IComponentHandler<GetAllFurnitureBaseRequest> getAllHandler, | ||||||
|  |         IComponentHandler<CreateFurnitureBaseRequest> createHandler, | ||||||
|  |         IComponentHandler<UpdateFurnitureBaseRequest> updateHandler, | ||||||
|  |         IComponentHandler<ChangeFurnitureBaseStatusRequest> changeStatusHandler, | ||||||
|  |         IFurnitureBasePort port) : ControllerBase | ||||||
|     { |     { | ||||||
|         private readonly IComponentHandler<GetFurnitureBaseByIdRequest> _getByIdHandler; |         private readonly IComponentHandler<GetFurnitureBaseByIdRequest> _getByIdHandler = getByIdHandler; | ||||||
|         private readonly IComponentHandler<GetAllFurnitureBaseRequest> _getAllHandler; |         private readonly IComponentHandler<GetAllFurnitureBaseRequest> _getAllHandler = getAllHandler; | ||||||
|         private readonly IComponentHandler<CreateFurnitureBaseRequest> _createHandler; |         private readonly IComponentHandler<CreateFurnitureBaseRequest> _createHandler = createHandler; | ||||||
|         private readonly IComponentHandler<UpdateFurnitureBaseRequest> _updateHandler; |         private readonly IComponentHandler<UpdateFurnitureBaseRequest> _updateHandler = updateHandler; | ||||||
|         private readonly IComponentHandler<ChangeFurnitureBaseStatusRequest> _changeStatusHandler; |         private readonly IComponentHandler<ChangeFurnitureBaseStatusRequest> _changeStatusHandler = changeStatusHandler; | ||||||
|         private readonly IFurnitureBasePort _port; |         private readonly IFurnitureBasePort _port = port; | ||||||
|  |  | ||||||
|         public FurnitureBaseController( |  | ||||||
|             IComponentHandler<GetFurnitureBaseByIdRequest> getByIdHandler, |  | ||||||
|             IComponentHandler<GetAllFurnitureBaseRequest> getAllHandler, |  | ||||||
|             IComponentHandler<CreateFurnitureBaseRequest> createHandler, |  | ||||||
|             IComponentHandler<UpdateFurnitureBaseRequest> updateHandler, |  | ||||||
|             IComponentHandler<ChangeFurnitureBaseStatusRequest> changeStatusHandler, |  | ||||||
|             IFurnitureBasePort port) |  | ||||||
|         { |  | ||||||
|             _getByIdHandler= getByIdHandler; |  | ||||||
|             _getAllHandler= getAllHandler; |  | ||||||
|             _createHandler= createHandler; |  | ||||||
|             _updateHandler= updateHandler; |  | ||||||
|             _changeStatusHandler= changeStatusHandler; |  | ||||||
|             _port= port; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         [HttpGet("GetAll")] |         [HttpGet("GetAll")] | ||||||
|         public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken) | ||||||
| @@ -45,7 +35,7 @@ namespace Core.Inventory.Service.API.Controllers | |||||||
|         [HttpPost("GetById")] |         [HttpPost("GetById")] | ||||||
|         public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken) |         public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture base identifier is required"); |             if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture base identifier is required"); | ||||||
|  |  | ||||||
|             await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); |             await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|             return _port.ViewModel; |             return _port.ViewModel; | ||||||
| @@ -68,7 +58,7 @@ namespace Core.Inventory.Service.API.Controllers | |||||||
|         [HttpPatch("ChangeStatus")] |         [HttpPatch("ChangeStatus")] | ||||||
|         public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture base identifier is required"); |             if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture base identifier is required"); | ||||||
|  |  | ||||||
|             await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); |             await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|             return _port.ViewModel; |             return _port.ViewModel; | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Input; | using Core.Inventory.Application.UseCases.Inventory.Input.Variant; | ||||||
| using Core.Inventory.Application.UseCases.Inventory.Ports; | using Core.Inventory.Application.UseCases.Inventory.Ports; | ||||||
| using Lib.Architecture.BuildingBlocks; | using Lib.Architecture.BuildingBlocks; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| @@ -12,38 +12,59 @@ namespace Core.Inventory.Service.API.Controllers | |||||||
|     [ApiController] |     [ApiController] | ||||||
|     public class FurnitureVariantController( |     public class FurnitureVariantController( | ||||||
|         IComponentHandler<GetFurnitureVariantByIdRequest> getByIdHandler, |         IComponentHandler<GetFurnitureVariantByIdRequest> getByIdHandler, | ||||||
|         IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> getAllHandler, |         IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> getAllMyModelIdHandler, | ||||||
|         IComponentHandler<CreateFurnitureVariantRequest> createHandler, |         IComponentHandler<CreateFurnitureVariantRequest> createHandler, | ||||||
|         IComponentHandler<UpdateFurnitureVariantRequest> updateHandler, |         IComponentHandler<UpdateFurnitureVariantRequest> updateHandler, | ||||||
|         IComponentHandler<ChangeFurnitureVariantStatusRequest> changeStatusHandler, |         IComponentHandler<ChangeFurnitureVariantStatusRequest> changeStatusHandler, | ||||||
|  |         IComponentHandler<GetFurnitureVariantsByIdsRequest> getByIdsHandler, | ||||||
|  |         IComponentHandler<GetAllFurnitureVariantRequest> getAllHandler, | ||||||
|         IFurnitureVariantPort port) : ControllerBase |         IFurnitureVariantPort port) : ControllerBase | ||||||
|     { |     { | ||||||
|         private readonly IComponentHandler<GetFurnitureVariantByIdRequest> _getByIdHandler = getByIdHandler; |         private readonly IComponentHandler<GetFurnitureVariantByIdRequest> _getByIdHandler = getByIdHandler; | ||||||
|         private readonly IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> _getAllHandler = getAllHandler; |         private readonly IComponentHandler<GetAllFurnitureVariantsByModelIdRequest> _getAllByModelIdHandler = getAllMyModelIdHandler; | ||||||
|         private readonly IComponentHandler<CreateFurnitureVariantRequest> _createHandler = createHandler; |         private readonly IComponentHandler<CreateFurnitureVariantRequest> _createHandler = createHandler; | ||||||
|         private readonly IComponentHandler<UpdateFurnitureVariantRequest> _updateHandler = updateHandler; |         private readonly IComponentHandler<UpdateFurnitureVariantRequest> _updateHandler = updateHandler; | ||||||
|         private readonly IComponentHandler<ChangeFurnitureVariantStatusRequest> _changeStatusHandler = changeStatusHandler; |         private readonly IComponentHandler<ChangeFurnitureVariantStatusRequest> _changeStatusHandler = changeStatusHandler; | ||||||
|  |         private readonly IComponentHandler<GetFurnitureVariantsByIdsRequest> _getByIdsHandler = getByIdsHandler; | ||||||
|  |         private readonly IComponentHandler<GetAllFurnitureVariantRequest> _getAllHandler = getAllHandler; | ||||||
|         private readonly IFurnitureVariantPort _port = port; |         private readonly IFurnitureVariantPort _port = port; | ||||||
|  |  | ||||||
|         [HttpGet("GetAllByModelId")] |         [HttpGet("GetAll")] | ||||||
|         public async Task<IActionResult> GetAllAsync([FromQuery] string modelId, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (string.IsNullOrEmpty(modelId)) return BadRequest("Model ID is required"); |             await _getAllHandler.ExecuteAsync(new GetAllFurnitureVariantRequest { }, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return _port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|             var request = new GetAllFurnitureVariantsByModelIdRequest { ModelId = modelId }; |         [HttpPost("GetAllByModelId")] | ||||||
|             await _getAllHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); |         public async Task<IActionResult> GetAllByModelIdAsync([FromBody] GetAllFurnitureVariantsByModelIdRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (string.IsNullOrEmpty(request?.ModelId)) return BadRequest("Model ID is required"); | ||||||
|  |  | ||||||
|  |             await _getAllByModelIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|             return _port.ViewModel; |             return _port.ViewModel; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         [HttpPost("GetById")] |         [HttpPost("GetById")] | ||||||
|         public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureVariantByIdRequest request, CancellationToken cancellationToken) |         public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureVariantByIdRequest request, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture variant identifier is required"); |             if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture variant identifier is required"); | ||||||
|  |  | ||||||
|             await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); |             await _getByIdHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|             return _port.ViewModel; |             return _port.ViewModel; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         [HttpPost("GetByIds")] | ||||||
|  |         public async Task<IActionResult> GetByIdsAsync([FromBody] GetFurnitureVariantsByIdsRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (request?.Ids is null || request.Ids.Length == 0) | ||||||
|  |                 return BadRequest("At least one furniture variant ID must be provided."); | ||||||
|  |  | ||||||
|  |             await _getByIdsHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return _port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         [HttpPost("Create")] |         [HttpPost("Create")] | ||||||
|         public async Task<IActionResult> CreateAsync([FromBody] CreateFurnitureVariantRequest request, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateAsync([FromBody] CreateFurnitureVariantRequest request, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -61,7 +82,7 @@ namespace Core.Inventory.Service.API.Controllers | |||||||
|         [HttpPatch("ChangeStatus")] |         [HttpPatch("ChangeStatus")] | ||||||
|         public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureVariantStatusRequest request, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureVariantStatusRequest request, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (string.IsNullOrEmpty(request?.Id)) return BadRequest("Furniture variant identifier is required"); |             if (string.IsNullOrEmpty(request?.MongoId)) return BadRequest("Furniture variant identifier is required"); | ||||||
|  |  | ||||||
|             await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); |             await _changeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|             return _port.ViewModel; |             return _port.ViewModel; | ||||||
|   | |||||||
							
								
								
									
										232
									
								
								Core.Inventory.Service.API/Controllers/ProductController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								Core.Inventory.Service.API/Controllers/ProductController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,232 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib.Inventory; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.Input; | ||||||
|  | using Core.Inventory.Application.UseCases.Product.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="ProductController"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces("application/json")] | ||||||
|  |     [ApiController] | ||||||
|  |     [AllowAnonymous] | ||||||
|  |     public class ProductController : ControllerBase | ||||||
|  |     { | ||||||
|  |         private readonly IComponentHandler<GetProductRequest> getProductHandler; | ||||||
|  |         private readonly IComponentHandler<GetAllProductsRequest> getAllProductsHandler; | ||||||
|  |         private readonly IComponentHandler<GetAllProductsByListRequest> getAllProductsByListHandler; | ||||||
|  |         private readonly IComponentHandler<CreateProductRequest> createProductHandler; | ||||||
|  |         private readonly IComponentHandler<UpdateProductRequest> updateProductHandler; | ||||||
|  |         private readonly IComponentHandler<ChangeProductStatusRequest> changeProductStatusHandler; | ||||||
|  |         private readonly IComponentHandler<DeleteProductRequest> deleteProductHandler; | ||||||
|  |         private readonly IProductPort port; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Handles all services and business rules related to <see cref="ProductController"/>. | ||||||
|  |         /// </summary> | ||||||
|  |         public ProductController( | ||||||
|  |             IComponentHandler<GetProductRequest> getProductHandler, | ||||||
|  |             IComponentHandler<GetAllProductsRequest> getAllProductsHandler, | ||||||
|  |             IComponentHandler<GetAllProductsByListRequest> getAllProductsByListHandler, | ||||||
|  |             IComponentHandler<CreateProductRequest> createProductHandler, | ||||||
|  |             IComponentHandler<UpdateProductRequest> updateProductHandler, | ||||||
|  |             IComponentHandler<ChangeProductStatusRequest> changeProductStatusHandler, | ||||||
|  |             IComponentHandler<DeleteProductRequest> deleteProductHandler, | ||||||
|  |             IProductPort port | ||||||
|  |             ) | ||||||
|  |         { | ||||||
|  |             this.createProductHandler = createProductHandler; | ||||||
|  |             this.updateProductHandler = updateProductHandler; | ||||||
|  |             this.changeProductStatusHandler = changeProductStatusHandler; | ||||||
|  |             this.getAllProductsHandler = getAllProductsHandler; | ||||||
|  |             this.getProductHandler = getProductHandler; | ||||||
|  |             this.getAllProductsByListHandler = getAllProductsByListHandler; | ||||||
|  |             this.deleteProductHandler = deleteProductHandler; | ||||||
|  |             this.port = port; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the Products. | ||||||
|  |         /// </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> GetAllProductsAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             await getAllProductsHandler.ExecuteAsync(new GetAllProductsRequest { }, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the Products by Product identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="request">The request containing the list of Product 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 Products found.</response> | ||||||
|  |         /// <response code="204">No content if no Products are found.</response> | ||||||
|  |         /// <response code="400">Bad request if the Product 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("GetProductList")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<ProductAdapter>), 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> GetAllProductsByListAsync([FromBody] GetAllProductsByListRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |             if (request == null || request.Products == null || !request.Products.Any()) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("Product identifiers are required."); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             await getAllProductsByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the Product 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> GetProductById([FromBody] GetProductRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |             if (request.Id == null || !request.Id.Any()) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("Invalid Product Id"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             await getProductHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Product. | ||||||
|  |         /// </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> CreateProductAsync([FromBody] CreateProductRequest newProduct, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             await createProductHandler.ExecuteAsync(newProduct, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full Product 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> UpdateProductAsync([FromBody] UpdateProductRequest request, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             await updateProductHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the Product. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="request">The request containing the product ID and new ProductStatus.</param> | ||||||
|  |         /// <returns>The <see cref="ProductAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The Product updates.</response> | ||||||
|  |         /// <response code="204">The Product not found.</response> | ||||||
|  |         /// <response code="400">The Product could not be updated.</response> | ||||||
|  |         /// <response code="401">The Product could not be updated.</response> | ||||||
|  |         /// <response code="412">The Product could not be updated.</response> | ||||||
|  |         /// <response code="422">The Product could not be updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [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> ChangeProductStatusAsync([FromBody] ChangeProductStatusRequest request, | ||||||
|  |                                                                      CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid Product identifier"); } | ||||||
|  |  | ||||||
|  |             await changeProductStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a Product by its MongoDB identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="request">The request containing the product ID to delete.</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 Product deleted successfully.</response> | ||||||
|  |         /// <response code="204">No content if the Product was not found.</response> | ||||||
|  |         /// <response code="400">Bad request if the Product ID is 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> | ||||||
|  |         [HttpDelete("Delete")] | ||||||
|  |         [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> DeleteProductAsync([FromBody] DeleteProductRequest request, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             if (string.IsNullOrEmpty(request.Id)) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("Invalid Product identifier"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             await deleteProductHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
							
								
								
									
										261
									
								
								Core.Inventory.Service.API/Controllers/TagController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										261
									
								
								Core.Inventory.Service.API/Controllers/TagController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,261 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.Application.UseCases.Tag.Input; | ||||||
|  | using Core.Inventory.Application.UseCases.Tag.Ports; | ||||||
|  | using Core.Inventory.Application.UseCases.TagType.Input; | ||||||
|  | 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 IComponentHandler<DeleteTagRequest> deleteTagHandler; | ||||||
|  |         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, | ||||||
|  |             IComponentHandler<DeleteTagRequest> deleteTagHandler, | ||||||
|  |             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.deleteTagHandler = deleteTagHandler; | ||||||
|  |             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; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a full Tag by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpDelete("Delete")] | ||||||
|  |         [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] DeleteTagRequest request, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             await deleteTagHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										208
									
								
								Core.Inventory.Service.API/Controllers/TagOverrideController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								Core.Inventory.Service.API/Controllers/TagOverrideController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,208 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||||
|  | using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.Service.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="TagOverrideController"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces("application/json")] | ||||||
|  |     [ApiController] | ||||||
|  |     [AllowAnonymous] | ||||||
|  |     public class TagOverrideController : ControllerBase | ||||||
|  |     { | ||||||
|  |         private readonly IComponentHandler<GetTagOverrideRequest> getTagOverrideHandler; | ||||||
|  |         private readonly IComponentHandler<GetAllTagOverridesRequest> getAllTagOverridesHandler; | ||||||
|  |         private readonly IComponentHandler<GetAllTagOverridesByListRequest> getAllTagOverridesByListHandler; | ||||||
|  |         private readonly IComponentHandler<CreateTagOverrideRequest> createTagOverrideHandler; | ||||||
|  |         private readonly IComponentHandler<UpdateTagOverrideRequest> updateTagOverrideHandler; | ||||||
|  |         private readonly IComponentHandler<ChangeTagOverrideStatusRequest> changeTagOverrideStatusHandler; | ||||||
|  |         private readonly IComponentHandler<DeleteTagOverrideRequest> deleteTagOverrideHandler; | ||||||
|  |         private readonly ITagOverridePort port; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Handles all services and business rules related to <see cref="TagOverrideController"/>. | ||||||
|  |         /// </summary> | ||||||
|  |         public TagOverrideController( | ||||||
|  |             IComponentHandler<GetTagOverrideRequest> getTagOverrideHandler, | ||||||
|  |             IComponentHandler<GetAllTagOverridesRequest> getAllTagOverridesHandler, | ||||||
|  |             IComponentHandler<GetAllTagOverridesByListRequest> getAllTagOverridesByListHandler, | ||||||
|  |             IComponentHandler<CreateTagOverrideRequest> createTagOverrideHandler, | ||||||
|  |             IComponentHandler<UpdateTagOverrideRequest> updateTagOverrideHandler, | ||||||
|  |             IComponentHandler<ChangeTagOverrideStatusRequest> changeTagOverrideStatusHandler, | ||||||
|  |             IComponentHandler<DeleteTagOverrideRequest> deleteTagOverrideHandler, | ||||||
|  |             ITagOverridePort port | ||||||
|  |             ) | ||||||
|  |         { | ||||||
|  |             this.createTagOverrideHandler = createTagOverrideHandler; | ||||||
|  |             this.updateTagOverrideHandler = updateTagOverrideHandler; | ||||||
|  |             this.changeTagOverrideStatusHandler = changeTagOverrideStatusHandler; | ||||||
|  |             this.getAllTagOverridesHandler = getAllTagOverridesHandler; | ||||||
|  |             this.getTagOverrideHandler = getTagOverrideHandler; | ||||||
|  |             this.getAllTagOverridesByListHandler = getAllTagOverridesByListHandler; | ||||||
|  |             this.deleteTagOverrideHandler = deleteTagOverrideHandler; | ||||||
|  |             this.port = port; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the TagOverrides. | ||||||
|  |         /// </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> GetAllTagOverridesAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             await getAllTagOverridesHandler.ExecuteAsync(new GetAllTagOverridesRequest { }, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the TagOverrides by TagOverride identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="request">The request containing the list of TagOverride 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 TagOverrides found.</response> | ||||||
|  |         /// <response code="204">No content if no TagOverrides are found.</response> | ||||||
|  |         /// <response code="400">Bad request if the TagOverride 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("GetTagOverrideList")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<TagOverrideAdapter>), 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> GetAllTagOverridesByListAsync([FromBody] GetAllTagOverridesByListRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |             if (request == null || request.TagOverrides == null || !request.TagOverrides.Any()) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("TagOverride identifiers are required."); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             await getAllTagOverridesByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the TagOverride 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> GetTagOverrideById([FromBody] GetTagOverrideRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |             if (request.Id == null || !request.Id.Any()) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("Invalid TagOverride Id"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             await getTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new TagOverride. | ||||||
|  |         /// </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> CreateTagOverrideAsync([FromBody] CreateTagOverrideRequest newTagOverride, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             await createTagOverrideHandler.ExecuteAsync(newTagOverride, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full TagOverride 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> UpdateTagOverrideAsync([FromBody] UpdateTagOverrideRequest request, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             await updateTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the TagOverride. | ||||||
|  |         /// </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> ChangeTagOverrideStatusAsync([FromBody] ChangeTagOverrideStatusRequest request, | ||||||
|  |                                                                      CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagOverride identifier"); } | ||||||
|  |  | ||||||
|  |             await changeTagOverrideStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Deletes a full TagOverride by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpDelete("Delete")] | ||||||
|  |         [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> UpdateTagOverrideAsync([FromBody] DeleteTagOverrideRequest request, CancellationToken cancellationToken = default) | ||||||
|  |         { | ||||||
|  |             await deleteTagOverrideHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return port.ViewModel; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user