Merge pull request 'Add TagOverride CRUD' (#4) from feature/add-tag-override-crud into development
Reviewed-on: #4 Reviewed-by: Sergio Matías <sergio.matias@agilewebs.com> Reviewed-by: efrain_marin <efrain.marin@agilewebs.com>
This commit is contained in:
		| @@ -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 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,212 @@ | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||
| using Core.Inventory.External.Clients; | ||||
| using Core.Inventory.External.Clients.Requests; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Lib.Architecture.BuildingBlocks.Helpers; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagOverride | ||||
| { | ||||
|     public class TagOverrideHandler : | ||||
|         IComponentHandler<ChangeTagOverrideStatusRequest>, | ||||
|         IComponentHandler<GetAllTagOverridesRequest>, | ||||
|         IComponentHandler<GetAllTagOverridesByListRequest>, | ||||
|         IComponentHandler<UpdateTagOverrideRequest>, | ||||
|         IComponentHandler<GetTagOverrideRequest>, | ||||
|         IComponentHandler<CreateTagOverrideRequest> | ||||
|     { | ||||
|         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; | ||||
|  | ||||
|         public TagOverrideHandler( | ||||
|             ITagOverridePort port, | ||||
|             IValidator<ChangeTagOverrideStatusRequest> changeTagOverrideStatusValidator, | ||||
|             IValidator<CreateTagOverrideRequest> registerTagOverrideValidator, | ||||
|             IValidator<UpdateTagOverrideRequest> updateTagOverrideValidator, | ||||
|             IValidator<GetAllTagOverridesByListRequest> TagOverridesByListValidator, | ||||
|             IInventoryServiceClient inventoryDALService) | ||||
|         { | ||||
|             _port = port ?? throw new ArgumentNullException(nameof(port)); | ||||
|             _changeTagOverrideStatusValidator = changeTagOverrideStatusValidator ?? throw new ArgumentNullException(nameof(changeTagOverrideStatusValidator)); | ||||
|             _registerTagOverrideValidator = registerTagOverrideValidator ?? throw new ArgumentNullException(nameof(registerTagOverrideValidator)); | ||||
|             _updateTagOverrideValidator = updateTagOverrideValidator ?? throw new ArgumentNullException(nameof(updateTagOverrideValidator)); | ||||
|             _inventoryServiceClient = inventoryDALService ?? throw new ArgumentNullException(nameof(inventoryDALService)); | ||||
|             _TagOverridesByListValidator = TagOverridesByListValidator ?? throw new ArgumentNullException(nameof(TagOverridesByListValidator)); | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.GetTagOverrideByIdAsync(command.Id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllTagOverridesRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllTagOverridesAsync().ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(GetAllTagOverridesByListRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_TagOverridesByListValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var _result = await _inventoryServiceClient.GetAllTagOverridesByListAsync(command.TagOverrides, cancellationToken).ConfigureAwait(false); | ||||
|                 if (!_result.Any()) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|                 _port.Success(_result.ToList()); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(ChangeTagOverrideStatusRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_changeTagOverrideStatusValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.ChangeStatusTagOverrideAsync(command.Id, command.Status, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(CreateTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_registerTagOverrideValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new TagOverrideRequest | ||||
|                 { | ||||
|                     TenantId = command.TenantId, | ||||
|                     BaseTagId = command.BaseTagId, | ||||
|                     OverrideTagId = command.OverrideTagId, | ||||
|                 }; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.CreateTagOverrideAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async ValueTask ExecuteAsync(UpdateTagOverrideRequest command, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 ArgumentNullException.ThrowIfNull(command); | ||||
|  | ||||
|                 if (!command.IsValid(_updateTagOverrideValidator)) | ||||
|                 { | ||||
|                     _port.ValidationErrors(command.Notifications); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 var request = new TagOverrideAdapter | ||||
|                 { | ||||
|                     Id = command.Id, | ||||
|                     TenantId = command.TenantId, | ||||
|                     BaseTagId = command.BaseTagId, | ||||
|                     OverrideTagId = command.OverrideTagId | ||||
|                 }; | ||||
|  | ||||
|                 string id = command.Id; | ||||
|  | ||||
|                 var result = await _inventoryServiceClient.UpdateTagOverrideAsync(request, id, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|                 if (result == null) | ||||
|                 { | ||||
|                     _port.NoContentSuccess(); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 _port.Success(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 ApiResponseHelper.EvaluatePort(ex, _port); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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,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."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,9 +1,4 @@ | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Core.Inventory.Application.UseCases.TagType.Input | ||||
| { | ||||
|   | ||||
| @@ -103,6 +103,28 @@ namespace Core.Inventory.External.Clients | ||||
|  | ||||
|         #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); | ||||
|  | ||||
|         #endregion | ||||
|  | ||||
|         #region Product | ||||
|  | ||||
|         [Get("/api/v1/Product")] | ||||
|   | ||||
| @@ -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!; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										187
									
								
								Core.Inventory.Service.API/Controllers/TagOverrideController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								Core.Inventory.Service.API/Controllers/TagOverrideController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,187 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Service.API.Controllers | ||||
| { | ||||
|     /// <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 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, | ||||
|             ITagOverridePort port | ||||
|             ) | ||||
|         { | ||||
|             this.createTagOverrideHandler = createTagOverrideHandler; | ||||
|             this.updateTagOverrideHandler = updateTagOverrideHandler; | ||||
|             this.changeTagOverrideStatusHandler = changeTagOverrideStatusHandler; | ||||
|             this.getAllTagOverridesHandler = getAllTagOverridesHandler; | ||||
|             this.getTagOverrideHandler = getTagOverrideHandler; | ||||
|             this.getAllTagOverridesByListHandler = getAllTagOverridesByListHandler; | ||||
|             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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -15,6 +15,11 @@ using Core.Inventory.Application.UseCases.Tag.Adapter; | ||||
| using Core.Inventory.Application.UseCases.Tag.Input; | ||||
| using Core.Inventory.Application.UseCases.Tag.Ports; | ||||
| using Core.Inventory.Application.UseCases.Tag.Validator; | ||||
| using Core.Inventory.Application.UseCases.TagOverride; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Adapter; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Input; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Ports; | ||||
| using Core.Inventory.Application.UseCases.TagOverride.Validator; | ||||
| using Core.Inventory.Application.UseCases.TagType; | ||||
| using Core.Inventory.Application.UseCases.TagType.Adapter; | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| @@ -132,6 +137,30 @@ namespace Core.Inventory.Service.API.Extensions | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             #region TagOverride Services | ||||
|  | ||||
|             services.AddScoped<ITagOverridePort, TagOverridePort>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagOverridesRequest>, TagOverrideHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetAllTagOverridesByListValidator>(); | ||||
|             services.AddScoped<IValidator<GetAllTagOverridesByListRequest>, GetAllTagOverridesByListValidator>(); | ||||
|             services.AddScoped<IComponentHandler<GetAllTagOverridesByListRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<CreateTagOverrideValidator>(); | ||||
|             services.AddScoped<IValidator<CreateTagOverrideRequest>, CreateTagOverrideValidator>(); | ||||
|             services.AddScoped<IComponentHandler<CreateTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<UpdateTagOverrideValidator>(); | ||||
|             services.AddScoped<IValidator<UpdateTagOverrideRequest>, UpdateTagOverrideValidator>(); | ||||
|             services.AddScoped<IComponentHandler<UpdateTagOverrideRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<ChangeTagOverrideStatusValidator>(); | ||||
|             services.AddScoped<IValidator<ChangeTagOverrideStatusRequest>, ChangeTagOverrideStatusValidator>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeTagOverrideStatusRequest>, TagOverrideHandler>(); | ||||
|  | ||||
|             #endregion | ||||
|  | ||||
|             #region Product Services | ||||
|  | ||||
|             services.AddScoped<IProductPort, ProductPort>(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user