From 1c780f9faccff4d3b4bbeaaf8f2790ccc5b9e273 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Sun, 28 Jan 2024 20:51:48 +0330 Subject: [PATCH] feat : ProductPage and CategoryPage complete category edit and creation , complete search for category and products page --- NetinaShop.Api/Controller/ProductController.cs | 4 ++-- .../CommandQueries/Queries/ProductQueries.cs | 8 +++++++- .../Handlers/Products/GetProductsQueryHandler.cs | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/NetinaShop.Api/Controller/ProductController.cs b/NetinaShop.Api/Controller/ProductController.cs index 270b57f..94bac24 100644 --- a/NetinaShop.Api/Controller/ProductController.cs +++ b/NetinaShop.Api/Controller/ProductController.cs @@ -32,8 +32,8 @@ public class ProductController : ICarterModule } // GET:Get All Entity - public async Task 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 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 GetAsync(Guid id, IMediator mediator,CancellationToken cancellationToken) diff --git a/NetinaShop.Domain/CommandQueries/Queries/ProductQueries.cs b/NetinaShop.Domain/CommandQueries/Queries/ProductQueries.cs index c6649ca..79b0752 100644 --- a/NetinaShop.Domain/CommandQueries/Queries/ProductQueries.cs +++ b/NetinaShop.Domain/CommandQueries/Queries/ProductQueries.cs @@ -2,4 +2,10 @@ public sealed record GetProductQuery(Guid Id) : IRequest; -public sealed record GetProductsQuery(int Page = 0 , QuerySortBy SortBy = QuerySortBy.None , Guid CategoryId = default , Guid BrandId = default , double MinPrice = -1 , double MaxPrice = 0) : IRequest>; \ No newline at end of file +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>; \ No newline at end of file diff --git a/NetinaShop.Repository/Handlers/Products/GetProductsQueryHandler.cs b/NetinaShop.Repository/Handlers/Products/GetProductsQueryHandler.cs index 6600329..6621055 100644 --- a/NetinaShop.Repository/Handlers/Products/GetProductsQueryHandler.cs +++ b/NetinaShop.Repository/Handlers/Products/GetProductsQueryHandler.cs @@ -11,6 +11,8 @@ public class GetProductsQueryHandler : IRequestHandler> Handle(GetProductsQuery request, CancellationToken cancellationToken) { var products = _repositoryWrapper.SetRepository().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