feat: added endpoint DeleteProduct
- fix: adapters package updated - fix: status property renamed
This commit is contained in:
@@ -202,5 +202,30 @@ namespace Core.Inventory.DAL.API.Controllers
|
|||||||
|
|
||||||
return Ok(result);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,12 +34,12 @@ namespace Core.Inventory.Domain.Contexts.Inventory.Request
|
|||||||
public string Description { get; set; } = null!;
|
public string Description { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the status of the product.
|
/// Gets or sets the productStatus of the product.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[BsonElement("status")]
|
[BsonElement("productStatus")]
|
||||||
[BsonRepresentation(BsonType.String)]
|
[BsonRepresentation(BsonType.String)]
|
||||||
[JsonPropertyName("status")]
|
[JsonPropertyName("productStatus")]
|
||||||
public string Status { get; set; } = null!;
|
public string ProductStatus { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the list of Tag Ids associated with this product.
|
/// Gets or sets the list of Tag Ids associated with this product.
|
||||||
|
|||||||
@@ -73,5 +73,13 @@ namespace Core.Inventory.Provider.Contracts
|
|||||||
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
/// the asynchronous execution of the service.</returns>
|
/// the asynchronous execution of the service.</returns>
|
||||||
ValueTask<ProductAdapter> RemoveTagFromProduct(string productId, string tagId, CancellationToken cancellationToken);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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="Core.Blueprint.Mongo" Version="1.0.0" />
|
<PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" />
|
||||||
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" />
|
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" />
|
||||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
public async ValueTask<ProductAdapter> ChangeProductStatus(string id, ProductStatus newStatus, CancellationToken cancellationToken)
|
public async ValueTask<ProductAdapter> ChangeProductStatus(string id, ProductStatus newStatus, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var entity = await repository.FindByIdAsync(id);
|
var entity = await repository.FindByIdAsync(id);
|
||||||
entity.Status = newStatus;
|
entity.ProductStatus = newStatus;
|
||||||
|
|
||||||
await repository.ReplaceOneAsync(entity);
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
@@ -190,5 +190,24 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
|
|
||||||
return product;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user