From e2ed3d100a6752fa98d2d08e56db06d08cb458d2 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Tue, 23 Jan 2024 15:20:42 +0330 Subject: [PATCH] refactor : add sort by main in category --- .version | 2 +- .../Controller/ProductCategoryController.cs | 4 ++-- NetinaShop.Api/NetinaShop.Api.csproj | 4 ++-- .../CommandQueries/Queries/ProductCategoryQueries.cs | 2 +- .../GetProductCategoriesQueryHandler.cs | 12 +++++++----- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.version b/.version index 0c6262a..5c8b739 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.0.0.3 \ No newline at end of file +0.0.0.4 \ No newline at end of file diff --git a/NetinaShop.Api/Controller/ProductCategoryController.cs b/NetinaShop.Api/Controller/ProductCategoryController.cs index d729352..626681f 100644 --- a/NetinaShop.Api/Controller/ProductCategoryController.cs +++ b/NetinaShop.Api/Controller/ProductCategoryController.cs @@ -30,8 +30,8 @@ public class ProductCategoryController : ICarterModule } // GET:Get All Entity - public async Task GetAllAsync([FromQuery]int? page,IMediator mediator, CancellationToken cancellationToken) - => TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(page),cancellationToken)); + public async Task GetAllAsync([FromQuery]int? page, [FromQuery]bool? sortByMain,IMediator mediator, CancellationToken cancellationToken) + => TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(page, sortByMain),cancellationToken)); // GET:Get An Entity By Id public async Task GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken) diff --git a/NetinaShop.Api/NetinaShop.Api.csproj b/NetinaShop.Api/NetinaShop.Api.csproj index b37f50d..ea989d0 100644 --- a/NetinaShop.Api/NetinaShop.Api.csproj +++ b/NetinaShop.Api/NetinaShop.Api.csproj @@ -6,8 +6,8 @@ enable true Linux - 0.0.0.2 - 0.0.0.2 + 0.0.0.4 + 0.0.0.4 diff --git a/NetinaShop.Domain/CommandQueries/Queries/ProductCategoryQueries.cs b/NetinaShop.Domain/CommandQueries/Queries/ProductCategoryQueries.cs index 2f1722f..bcc12a4 100644 --- a/NetinaShop.Domain/CommandQueries/Queries/ProductCategoryQueries.cs +++ b/NetinaShop.Domain/CommandQueries/Queries/ProductCategoryQueries.cs @@ -1,4 +1,4 @@ namespace NetinaShop.Domain.CommandQueries.Queries; public record GetProductCategoryQuery(Guid Id) : IRequest; -public record GetProductCategoriesQuery(int? page) : IRequest>; \ No newline at end of file +public record GetProductCategoriesQuery(int? Page , bool? SortByMain) : IRequest>; \ No newline at end of file diff --git a/NetinaShop.Repository/Handlers/ProductCategories/GetProductCategoriesQueryHandler.cs b/NetinaShop.Repository/Handlers/ProductCategories/GetProductCategoriesQueryHandler.cs index cd55a3e..bfb575f 100644 --- a/NetinaShop.Repository/Handlers/ProductCategories/GetProductCategoriesQueryHandler.cs +++ b/NetinaShop.Repository/Handlers/ProductCategories/GetProductCategoriesQueryHandler.cs @@ -13,12 +13,12 @@ public class GetProductCategoriesQueryHandler : IRequestHandler> Handle(GetProductCategoriesQuery request, CancellationToken cancellationToken) { List groupCats; - if (request.page != null) + if (request.Page != null) { groupCats = await _repositoryWrapper.SetRepository() .TableNoTracking - .OrderByDescending(c=>c.CreatedAt) - .Skip(request.page.Value * 15).Take(15) + .OrderByDescending(c => c.CreatedAt) + .Skip(request.Page.Value * 15).Take(15) .Select(CategoryMapper.ProjectToSDto) .ToListAsync(cancellationToken); } @@ -30,11 +30,13 @@ public class GetProductCategoriesQueryHandler : IRequestHandler c.ParentId == cat.Id).ToList(); - var mainCats = groupCats.Where(c => c.IsMain).ToList(); + return groupCats.Where(c => c.IsMain).ToList(); - return mainCats; } } \ No newline at end of file