Add TagType CRUD
This commit is contained in:
		
							
								
								
									
										187
									
								
								Core.Inventory.Service.API/Controllers/TagTypeController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								Core.Inventory.Service.API/Controllers/TagTypeController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,187 @@ | ||||
| using Asp.Versioning; | ||||
| using Core.Adapters.Lib; | ||||
| using Core.Inventory.Application.UseCases.TagType.Input; | ||||
| using Core.Inventory.Application.UseCases.TagType.Ports; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace Core.Inventory.Service.API.Controllers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="TagTypeController"/>. | ||||
|     /// </summary> | ||||
|     [ApiVersion("1.0")] | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [ApiController] | ||||
|     [AllowAnonymous] | ||||
|     public class TagTypeController : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetTagTypeRequest> getTagTypeHandler; | ||||
|         private readonly IComponentHandler<GetAllTagTypesRequest> getAllTagTypesHandler; | ||||
|         private readonly IComponentHandler<GetAllTagTypesByListRequest> getAllTagTypesByListHandler; | ||||
|         private readonly IComponentHandler<CreateTagTypeRequest> createTagTypeHandler; | ||||
|         private readonly IComponentHandler<UpdateTagTypeRequest> updateTagTypeHandler; | ||||
|         private readonly IComponentHandler<ChangeTagTypeStatusRequest> changeTagTypeStatusHandler; | ||||
|         private readonly ITagTypePort port; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Handles all services and business rules related to <see cref="TagTypeController"/>. | ||||
|         /// </summary> | ||||
|         public TagTypeController( | ||||
|             IComponentHandler<GetTagTypeRequest> getTagTypeHandler, | ||||
|             IComponentHandler<GetAllTagTypesRequest> getAllTagTypesHandler, | ||||
|             IComponentHandler<GetAllTagTypesByListRequest> getAllTagTypesByListHandler, | ||||
|             IComponentHandler<CreateTagTypeRequest> createTagTypeHandler, | ||||
|             IComponentHandler<UpdateTagTypeRequest> updateTagTypeHandler, | ||||
|             IComponentHandler<ChangeTagTypeStatusRequest> changeTagTypeStatusHandler, | ||||
|             ITagTypePort port | ||||
|             ) | ||||
|         { | ||||
|             this.createTagTypeHandler = createTagTypeHandler; | ||||
|             this.updateTagTypeHandler = updateTagTypeHandler; | ||||
|             this.changeTagTypeStatusHandler = changeTagTypeStatusHandler; | ||||
|             this.getAllTagTypesHandler = getAllTagTypesHandler; | ||||
|             this.getTagTypeHandler = getTagTypeHandler; | ||||
|             this.getAllTagTypesByListHandler = getAllTagTypesByListHandler; | ||||
|             this.port = port; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the TagTypes. | ||||
|         /// </summary> | ||||
|         [HttpGet("GetAll")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> GetAllTagTypesAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             await getAllTagTypesHandler.ExecuteAsync(new GetAllTagTypesRequest { }, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the TagTypes by TagType identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">The request containing the list of TagType identifiers.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||
|         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||
|         /// <response code="200">The TagTypes found.</response> | ||||
|         /// <response code="204">No content if no TagTypes are found.</response> | ||||
|         /// <response code="400">Bad request if the TagType identifiers are missing or invalid.</response> | ||||
|         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||
|         /// <response code="412">Precondition failed if the request does not meet expected conditions.</response> | ||||
|         /// <response code="422">Unprocessable entity if the request cannot be processed.</response> | ||||
|         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||
|         [HttpPost] | ||||
|         [Route("GetTagTypeList")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<TagTypeAdapter>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> GetAllTagTypesByListAsync([FromBody] GetAllTagTypesByListRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request == null || request.TagTypes == null || !request.TagTypes.Any()) | ||||
|             { | ||||
|                 return BadRequest("TagType identifiers are required."); | ||||
|             } | ||||
|  | ||||
|             await getAllTagTypesByListHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the TagType by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPost] | ||||
|         [Route("GetById")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> GetTagTypeById([FromBody] GetTagTypeRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             if (request.Id == null || !request.Id.Any()) | ||||
|             { | ||||
|                 return BadRequest("Invalid TagType Id"); | ||||
|             } | ||||
|  | ||||
|             await getTagTypeHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new TagType. | ||||
|         /// </summary> | ||||
|         [HttpPost("Create")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> CreateTagTypeAsync([FromBody] CreateTagTypeRequest newTagType, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await createTagTypeHandler.ExecuteAsync(newTagType, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a full TagType by identifier. | ||||
|         /// </summary> | ||||
|         [HttpPut("Update")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> UpdateTagTypeAsync([FromBody] UpdateTagTypeRequest request, CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             await updateTagTypeHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the TagType. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("ChangeStatus")] | ||||
|         [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||
|         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||
|         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||
|         public async Task<IActionResult> ChangeTagTypeStatusAsync([FromBody] ChangeTagTypeStatusRequest request, | ||||
|                                                                      CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagType identifier"); } | ||||
|  | ||||
|             await changeTagTypeStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); | ||||
|  | ||||
|             return port.ViewModel; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Oscar Morales
					Oscar Morales