feat: Add bulk update functionalities for product prices and stock, along with low stock query support
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
using BackOffice.BFF.Application.Common.Models;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetLowStockProducts;
|
||||
|
||||
public record GetLowStockProductsQuery : IRequest<GetLowStockProductsResponseDto>
|
||||
{
|
||||
public int Threshold { get; init; } = 10;
|
||||
public int PageIndex { get; init; } = 1;
|
||||
public int PageSize { get; init; } = 20;
|
||||
public bool? IsClubExclusive { get; init; }
|
||||
}
|
||||
|
||||
public class GetLowStockProductsResponseDto
|
||||
{
|
||||
public MetaData MetaData { get; set; } = new();
|
||||
public List<LowStockProductDto> Products { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LowStockProductDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public int RemainingCount { get; set; }
|
||||
public long Price { get; set; }
|
||||
public bool IsClubExclusive { get; set; }
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.Products;
|
||||
|
||||
namespace BackOffice.BFF.Application.ProductsCQ.Queries.GetLowStockProducts;
|
||||
|
||||
public class GetLowStockProductsQueryHandler : IRequestHandler<GetLowStockProductsQuery, GetLowStockProductsResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetLowStockProductsQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLowStockProductsResponseDto> Handle(GetLowStockProductsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var protoRequest = new GetLowStockProductsRequest
|
||||
{
|
||||
Threshold = request.Threshold,
|
||||
PageIndex = request.PageIndex,
|
||||
PageSize = request.PageSize
|
||||
};
|
||||
|
||||
if (request.IsClubExclusive.HasValue)
|
||||
{
|
||||
protoRequest.IsClubExclusive = request.IsClubExclusive.Value;
|
||||
}
|
||||
|
||||
var response = await _context.Products.GetLowStockProductsAsync(protoRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return response.Adapt<GetLowStockProductsResponseDto>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user