Add TagOverride CRUD
This commit is contained in:
		
							
								
								
									
										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
	 Oscar Morales
					Oscar Morales