diff --git a/Core.Inventory.DAL.API/Controllers/ProductController.cs b/Core.Inventory.DAL.API/Controllers/ProductController.cs
index 8f17be9..274b491 100644
--- a/Core.Inventory.DAL.API/Controllers/ProductController.cs
+++ b/Core.Inventory.DAL.API/Controllers/ProductController.cs
@@ -202,5 +202,30 @@ namespace Core.Inventory.DAL.API.Controllers
return Ok(result);
}
+
+ ///
+ /// Deletes a Product by its MongoDB identifier.
+ ///
+ /// The Product MongoDB identifier.
+ /// The result of the delete operation.
+ /// The Product deleted successfully.
+ /// The Product not found.
+ /// The service internal error.
+ [HttpDelete]
+ [Route("{id}")]
+ [Consumes(MimeTypes.ApplicationJson)]
+ [Produces(MimeTypes.ApplicationJson)]
+ [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
+ public async Task 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);
+ }
}
}
\ No newline at end of file
diff --git a/Core.Inventory.Domain/Contexts/Inventory/Request/ProductRequest.cs b/Core.Inventory.Domain/Contexts/Inventory/Request/ProductRequest.cs
index dbadbfb..5ac418d 100644
--- a/Core.Inventory.Domain/Contexts/Inventory/Request/ProductRequest.cs
+++ b/Core.Inventory.Domain/Contexts/Inventory/Request/ProductRequest.cs
@@ -34,12 +34,12 @@ namespace Core.Inventory.Domain.Contexts.Inventory.Request
public string Description { get; set; } = null!;
///
- /// Gets or sets the status of the product.
+ /// Gets or sets the productStatus of the product.
///
- [BsonElement("status")]
+ [BsonElement("productStatus")]
[BsonRepresentation(BsonType.String)]
- [JsonPropertyName("status")]
- public string Status { get; set; } = null!;
+ [JsonPropertyName("productStatus")]
+ public string ProductStatus { get; set; } = null!;
///
/// Gets or sets the list of Tag Ids associated with this product.
diff --git a/Core.Inventory.Provider/Contracts/IProductProvider.cs b/Core.Inventory.Provider/Contracts/IProductProvider.cs
index 323bec3..aeec7a9 100644
--- a/Core.Inventory.Provider/Contracts/IProductProvider.cs
+++ b/Core.Inventory.Provider/Contracts/IProductProvider.cs
@@ -73,5 +73,13 @@ namespace Core.Inventory.Provider.Contracts
/// A representing
/// the asynchronous execution of the service.
ValueTask RemoveTagFromProduct(string productId, string tagId, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes a Product by its MongoDB identifier.
+ ///
+ /// The Product MongoDB identifier.
+ /// A representing
+ /// the asynchronous execution of the service.
+ ValueTask DeleteProduct(string productId, CancellationToken cancellationToken);
}
}
\ No newline at end of file
diff --git a/Core.Inventory.Provider/Core.Inventory.Provider.csproj b/Core.Inventory.Provider/Core.Inventory.Provider.csproj
index bbcdffe..7d293f8 100644
--- a/Core.Inventory.Provider/Core.Inventory.Provider.csproj
+++ b/Core.Inventory.Provider/Core.Inventory.Provider.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/Core.Inventory.Provider/Providers/Inventory/ProductProvider.cs b/Core.Inventory.Provider/Providers/Inventory/ProductProvider.cs
index e3c2b7e..807646c 100644
--- a/Core.Inventory.Provider/Providers/Inventory/ProductProvider.cs
+++ b/Core.Inventory.Provider/Providers/Inventory/ProductProvider.cs
@@ -125,7 +125,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
public async ValueTask 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 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;
}
+
+ ///
+ /// Deletes a Product by its MongoDB identifier.
+ ///
+ /// The Product MongoDB identifier.
+ /// A representing
+ /// the asynchronous execution of the service.
+ public async ValueTask DeleteProduct(string productId, CancellationToken cancellationToken)
+ {
+ try
+ {
+ await repository.DeleteByIdAsync(productId);
+ return true;
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
}
-}
\ No newline at end of file
+}
\ No newline at end of file