feat: added endpoint DeleteProduct

- fix: adapters package updated
- fix: status property renamed
This commit is contained in:
Efra 2025-08-05 20:54:55 -06:00
parent a706f96bd8
commit 17c94d1095
5 changed files with 60 additions and 8 deletions

View File

@ -202,5 +202,30 @@ namespace Core.Inventory.DAL.API.Controllers
return Ok(result);
}
/// <summary>
/// Deletes a Product by its MongoDB identifier.
/// </summary>
/// <param name="id">The Product MongoDB identifier.</param>
/// <returns>The result of the delete operation.</returns>
/// <response code="200">The Product deleted successfully.</response>
/// <response code="404">The Product not found.</response>
/// <response code="500">The service internal error.</response>
[HttpDelete]
[Route("{id}")]
[Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
public async Task<IActionResult> DeleteProduct([FromRoute] string id, CancellationToken cancellationToken)
{
var result = await service.DeleteProduct(id, cancellationToken).ConfigureAwait(false);
if (!result)
{
return NotFound("Product not found");
}
return Ok(result);
}
}
}

View File

@ -34,12 +34,12 @@ namespace Core.Inventory.Domain.Contexts.Inventory.Request
public string Description { get; set; } = null!;
/// <summary>
/// Gets or sets the status of the product.
/// Gets or sets the productStatus of the product.
/// </summary>
[BsonElement("status")]
[BsonElement("productStatus")]
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("status")]
public string Status { get; set; } = null!;
[JsonPropertyName("productStatus")]
public string ProductStatus { get; set; } = null!;
/// <summary>
/// Gets or sets the list of Tag Ids associated with this product.

View File

@ -73,5 +73,13 @@ namespace Core.Inventory.Provider.Contracts
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
/// the asynchronous execution of the service.</returns>
ValueTask<ProductAdapter> RemoveTagFromProduct(string productId, string tagId, CancellationToken cancellationToken);
/// <summary>
/// Deletes a Product by its MongoDB identifier.
/// </summary>
/// <param name="productId">The Product MongoDB identifier.</param>
/// <returns>A <see cref="{Task{bool}}"/> representing
/// the asynchronous execution of the service.</returns>
ValueTask<bool> DeleteProduct(string productId, CancellationToken cancellationToken);
}
}

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Adapters.Lib" Version="1.0.11" />
<PackageReference Include="Adapters.Lib" Version="1.0.13" />
<PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" />
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" />
<PackageReference Include="Mapster" Version="7.4.0" />

View File

@ -125,7 +125,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
public async ValueTask<ProductAdapter> ChangeProductStatus(string id, ProductStatus newStatus, CancellationToken cancellationToken)
{
var entity = await repository.FindByIdAsync(id);
entity.Status = newStatus;
entity.ProductStatus = newStatus;
await repository.ReplaceOneAsync(entity);
@ -180,7 +180,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
public async ValueTask<ProductAdapter> RemoveTagFromProduct(string productId, string tagId, CancellationToken cancellationToken)
{
var product = await repository.FindByIdAsync(productId);
if (product != null)
{
var objectId = ObjectId.Parse(tagId);
@ -190,5 +190,24 @@ namespace Core.Inventory.Provider.Providers.Inventory
return product;
}
/// <summary>
/// Deletes a Product by its MongoDB identifier.
/// </summary>
/// <param name="productId">The Product MongoDB identifier.</param>
/// <returns>A <see cref="{Task{bool}}"/> representing
/// the asynchronous execution of the service.</returns>
public async ValueTask<bool> DeleteProduct(string productId, CancellationToken cancellationToken)
{
try
{
await repository.DeleteByIdAsync(productId);
return true;
}
catch (Exception)
{
throw;
}
}
}
}
}