2 Commits

Author SHA1 Message Date
cf957eb3e0 Merge pull request 'feat: added endpoint DeleteProduct (BFF)' (#5) from feature/create-Product-and-ProductTag-CRUD into development
Reviewed-on: #5
Reviewed-by: Sergio Matías <sergio.matias@agilewebs.com>
Reviewed-by: OscarMmtz <oscar.morales@agilewebs.com>
2025-08-07 22:12:05 +00:00
bed3202892 feat: added endpoint DeleteProduct
- feat: Added Product controller and endpoints
- feat: package updated
2025-08-06 18:11:19 -06:00
6 changed files with 67 additions and 3 deletions

View File

@@ -171,6 +171,15 @@ namespace Core.Inventory.BFF.API.Controllers
/// <summary> /// <summary>
/// Changes the status of the Product. /// Changes the status of the Product.
/// </summary> /// </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] [HttpPatch]
[Route("ChangeStatus")] [Route("ChangeStatus")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
@@ -256,5 +265,43 @@ namespace Core.Inventory.BFF.API.Controllers
throw; throw;
} }
} }
/// <summary>
/// Deletes a Product by its 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> DeleteProductService([FromBody] DeleteProductRequest request, CancellationToken cancellationToken)
{
try
{
logger.LogInformation($"{nameof(DeleteProductService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid Product identifier"); }
return await Handle(() => inventoryServiceClient.DeleteProductService(request, cancellationToken)).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError($"{nameof(DeleteProductService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
throw;
}
}
} }
} }

View File

@@ -154,6 +154,9 @@ namespace Core.Inventory.External.Clients.Inventory
[Delete("/api/v1/Product/RemoveTag")] [Delete("/api/v1/Product/RemoveTag")]
Task<ApiResponse<ProductAdapter>> RemoveTagFromProductAsync([Header("TrackingId")][Body] RemoveTagFromProductRequest request, CancellationToken cancellationToken = default); Task<ApiResponse<ProductAdapter>> RemoveTagFromProductAsync([Header("TrackingId")][Body] RemoveTagFromProductRequest request, CancellationToken cancellationToken = default);
[Delete("/api/v1/Product/Delete")]
Task<ApiResponse<ProductAdapter>> DeleteProductService([Header("TrackingId")][Body] DeleteProductRequest request, CancellationToken cancellationToken = default);
#endregion #endregion
} }
} }

View File

@@ -5,7 +5,7 @@ namespace Core.Inventory.External.Clients.Inventory.Requests.Product
public string TenantId { get; set; } = null!; public string TenantId { get; set; } = null!;
public string ProductName { get; set; } = null!; public string ProductName { get; set; } = null!;
public string Description { get; set; } = null!; public string Description { get; set; } = null!;
public string Status { get; set; } = null!; public string ProductStatus { get; set; } = null!;
public List<string> TagIds { get; set; } = new List<string>(); public List<string> TagIds { get; set; } = new List<string>();
} }
} }

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.External.Clients.Inventory.Requests.Product
{
public class DeleteProductRequest : Notificator, ICommand
{
public string Id { get; set; } = null!;
public bool Validate()
{
return Id != null;
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Core.Inventory.External.Clients.Inventory.Requests.Product
public string TenantId { get; set; } = null!; public string TenantId { get; set; } = null!;
public string ProductName { get; set; } = null!; public string ProductName { get; set; } = null!;
public string Description { get; set; } = null!; public string Description { get; set; } = null!;
public string Status { get; set; } = null!; public string ProductStatus { get; set; } = null!;
public List<string> TagIds { get; set; } = new List<string>(); public List<string> TagIds { get; set; } = new List<string>();
} }
} }

View File

@@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Adapters.Lib" Version="1.0.11" /> <PackageReference Include="Adapters.Lib" Version="1.0.13" />
<PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" />
<PackageReference Include="Refit" Version="8.0.0" /> <PackageReference Include="Refit" Version="8.0.0" />
</ItemGroup> </ItemGroup>