Re-factor on service
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| 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 Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| @@ -10,30 +10,20 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||
|     [Produces("application/json")] | ||||
|     [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<GetAllFurnitureBaseRequest> _getAllHandler; | ||||
|         private readonly IComponentHandler<CreateFurnitureBaseRequest> _createHandler; | ||||
|         private readonly IComponentHandler<UpdateFurnitureBaseRequest> _updateHandler; | ||||
|         private readonly IComponentHandler<ChangeFurnitureBaseStatusRequest> _changeStatusHandler; | ||||
|         private readonly IFurnitureBasePort _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; | ||||
|         } | ||||
|         private readonly IComponentHandler<GetFurnitureBaseByIdRequest> _getByIdHandler = getByIdHandler; | ||||
|         private readonly IComponentHandler<GetAllFurnitureBaseRequest> _getAllHandler = getAllHandler; | ||||
|         private readonly IComponentHandler<CreateFurnitureBaseRequest> _createHandler = createHandler; | ||||
|         private readonly IComponentHandler<UpdateFurnitureBaseRequest> _updateHandler = updateHandler; | ||||
|         private readonly IComponentHandler<ChangeFurnitureBaseStatusRequest> _changeStatusHandler = changeStatusHandler; | ||||
|         private readonly IFurnitureBasePort _port = port; | ||||
|  | ||||
|         [HttpGet("GetAll")] | ||||
|         public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken) | ||||
| @@ -45,7 +35,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         [HttpPost("GetById")] | ||||
|         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); | ||||
|             return _port.ViewModel; | ||||
| @@ -68,7 +58,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         [HttpPatch("ChangeStatus")] | ||||
|         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); | ||||
|             return _port.ViewModel; | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| 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 Lib.Architecture.BuildingBlocks; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| @@ -16,6 +16,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         IComponentHandler<CreateFurnitureVariantRequest> createHandler, | ||||
|         IComponentHandler<UpdateFurnitureVariantRequest> updateHandler, | ||||
|         IComponentHandler<ChangeFurnitureVariantStatusRequest> changeStatusHandler, | ||||
|         IComponentHandler<GetFurnitureVariantsByIdsRequest> getByIdsHandler, | ||||
|         IFurnitureVariantPort port) : ControllerBase | ||||
|     { | ||||
|         private readonly IComponentHandler<GetFurnitureVariantByIdRequest> _getByIdHandler = getByIdHandler; | ||||
| @@ -23,6 +24,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         private readonly IComponentHandler<CreateFurnitureVariantRequest> _createHandler = createHandler; | ||||
|         private readonly IComponentHandler<UpdateFurnitureVariantRequest> _updateHandler = updateHandler; | ||||
|         private readonly IComponentHandler<ChangeFurnitureVariantStatusRequest> _changeStatusHandler = changeStatusHandler; | ||||
|         private readonly IComponentHandler<GetFurnitureVariantsByIdsRequest> _getByIdsHandler = getByIdsHandler; | ||||
|         private readonly IFurnitureVariantPort _port = port; | ||||
|  | ||||
|         [HttpGet("GetAllByModelId")] | ||||
| @@ -38,12 +40,23 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         [HttpPost("GetById")] | ||||
|         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); | ||||
|             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")] | ||||
|         public async Task<IActionResult> CreateAsync([FromBody] CreateFurnitureVariantRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
| @@ -61,7 +74,7 @@ namespace Core.Inventory.Service.API.Controllers | ||||
|         [HttpPatch("ChangeStatus")] | ||||
|         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); | ||||
|             return _port.ViewModel; | ||||
|   | ||||
| @@ -1,8 +1,10 @@ | ||||
| using Core.Inventory.Application.UseCases.Inventory; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Adapter; | ||||
| 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.Validator; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Base; | ||||
| using Core.Inventory.Application.UseCases.Inventory.Validator.Variant; | ||||
| using FluentValidation; | ||||
| using Lib.Architecture.BuildingBlocks; | ||||
|  | ||||
| @@ -42,6 +44,7 @@ namespace Core.Inventory.Service.API.Extensions | ||||
|             services.AddScoped<IComponentHandler<CreateFurnitureVariantRequest>, InventoryHandler>(); | ||||
|             services.AddScoped<IComponentHandler<UpdateFurnitureVariantRequest>, InventoryHandler>(); | ||||
|             services.AddScoped<IComponentHandler<ChangeFurnitureVariantStatusRequest>, InventoryHandler>(); | ||||
|             services.AddScoped<IComponentHandler<GetFurnitureVariantsByIdsRequest>, InventoryHandler>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<CreateFurnitureVariantValidator>(); | ||||
|             services.AddScoped<IValidator<CreateFurnitureVariantRequest>, CreateFurnitureVariantValidator>(); | ||||
| @@ -57,6 +60,9 @@ namespace Core.Inventory.Service.API.Extensions | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetAllFurnitureVariantsByModelIdValidator>(); | ||||
|             services.AddScoped<IValidator<GetAllFurnitureVariantsByModelIdRequest>, GetAllFurnitureVariantsByModelIdValidator>(); | ||||
|  | ||||
|             services.AddValidatorsFromAssemblyContaining<GetFurnitureVariantsByIdsValidator>(); | ||||
|             services.AddScoped<IValidator<GetFurnitureVariantsByIdsRequest>, GetFurnitureVariantsByIdsValidator>(); | ||||
|             #endregion | ||||
|  | ||||
|             return services; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user