feat: added endpoint DeleteProduct

- fix: adapters package updated
- fix: status property renamed
This commit is contained in:
2025-08-05 22:14:27 -06:00
parent ab3863943d
commit b529d905b1
13 changed files with 133 additions and 8 deletions

View File

@@ -24,6 +24,7 @@ namespace Core.Inventory.Service.API.Controllers
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>
@@ -36,6 +37,7 @@ namespace Core.Inventory.Service.API.Controllers
IComponentHandler<CreateProductRequest> createProductHandler,
IComponentHandler<UpdateProductRequest> updateProductHandler,
IComponentHandler<ChangeProductStatusRequest> changeProductStatusHandler,
IComponentHandler<DeleteProductRequest> deleteProductHandler,
IProductPort port
)
{
@@ -45,6 +47,7 @@ namespace Core.Inventory.Service.API.Controllers
this.getAllProductsHandler = getAllProductsHandler;
this.getProductHandler = getProductHandler;
this.getAllProductsByListHandler = getAllProductsByListHandler;
this.deleteProductHandler = deleteProductHandler;
this.port = port;
}
@@ -165,6 +168,15 @@ namespace Core.Inventory.Service.API.Controllers
/// <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)]
@@ -183,5 +195,38 @@ namespace Core.Inventory.Service.API.Controllers
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;
}
}
}

View File

@@ -154,6 +154,10 @@ namespace Core.Inventory.Service.API.Extensions
services.AddScoped<IValidator<ChangeProductStatusRequest>, ChangeProductStatusValidator>();
services.AddScoped<IComponentHandler<ChangeProductStatusRequest>, ProductHandler>();
services.AddValidatorsFromAssemblyContaining<DeleteProductValidator>();
services.AddScoped<IValidator<DeleteProductRequest>, DeleteProductValidator>();
services.AddScoped<IComponentHandler<DeleteProductRequest>, ProductHandler>();
#endregion
return services;