feat : ProductPage and CategoryPage

complete category edit and creation , complete search for category and products page
release
Amir Hossein Khademi 2024-01-28 20:51:48 +03:30
parent cfb6238f82
commit 1c780f9fac
3 changed files with 12 additions and 4 deletions

View File

@ -32,8 +32,8 @@ public class ProductController : ICarterModule
}
// GET:Get All Entity
public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery] QuerySortBy? sortBy,[FromQuery] Guid? categoryId , [FromQuery]Guid? brandId , [FromQuery]double? minPrice , [FromQuery] double? maxPrice, IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetProductsQuery(page,SortBy: sortBy ?? 0 , CategoryId: categoryId ?? default , BrandId: brandId ?? default , MinPrice: minPrice ?? -1 , MaxPrice:maxPrice ?? 0),cancellationToken));
public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery]string? productName, [FromQuery] QuerySortBy? sortBy,[FromQuery] Guid? categoryId , [FromQuery]Guid? brandId , [FromQuery]double? minPrice , [FromQuery] double? maxPrice, IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetProductsQuery(page,SortBy: sortBy ?? 0 ,ProductName: productName, CategoryId: categoryId ?? default , BrandId: brandId ?? default , MinPrice: minPrice ?? -1 , MaxPrice:maxPrice ?? 0),cancellationToken));
// GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, IMediator mediator,CancellationToken cancellationToken)

View File

@ -2,4 +2,10 @@
public sealed record GetProductQuery(Guid Id) : IRequest<ProductLDto>;
public sealed record GetProductsQuery(int Page = 0 , QuerySortBy SortBy = QuerySortBy.None , Guid CategoryId = default , Guid BrandId = default , double MinPrice = -1 , double MaxPrice = 0) : IRequest<List<ProductSDto>>;
public sealed record GetProductsQuery(int Page = 0 ,
string? ProductName = default,
QuerySortBy SortBy = QuerySortBy.None ,
Guid CategoryId = default ,
Guid BrandId = default ,
double MinPrice = -1 ,
double MaxPrice = 0) : IRequest<List<ProductSDto>>;

View File

@ -11,6 +11,8 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, List<Pr
public async Task<List<ProductSDto>> Handle(GetProductsQuery request, CancellationToken cancellationToken)
{
var products = _repositoryWrapper.SetRepository<Product>().TableNoTracking;
if (request.ProductName != null)
products = products.Where( p => p.PersianName.ToLower().Trim().Contains(request.ProductName.ToLower().Trim()));
if (request.CategoryId != default)
products = products.Where(p => p.CategoryId == request.CategoryId);
if (request.BrandId != default)
@ -32,7 +34,7 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, List<Pr
}
var productSDtos = await products.Skip(request.Page * 20)
.Take(10)
.Take(20)
.Select(ProductMapper.ProjectToSDto)
.ToListAsync(cancellationToken);