refactor : add sort by main in category
parent
f29a1a181e
commit
e2ed3d100a
|
@ -30,8 +30,8 @@ public class ProductCategoryController : ICarterModule
|
|||
}
|
||||
|
||||
// GET:Get All Entity
|
||||
public async Task<IResult> GetAllAsync([FromQuery]int? page,IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(page),cancellationToken));
|
||||
public async Task<IResult> 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<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<AssemblyVersion>0.0.0.2</AssemblyVersion>
|
||||
<FileVersion>0.0.0.2</FileVersion>
|
||||
<AssemblyVersion>0.0.0.4</AssemblyVersion>
|
||||
<FileVersion>0.0.0.4</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.Domain.CommandQueries.Queries;
|
||||
|
||||
public record GetProductCategoryQuery(Guid Id) : IRequest<ProductCategoryLDto>;
|
||||
public record GetProductCategoriesQuery(int? page) : IRequest<List<ProductCategorySDto>>;
|
||||
public record GetProductCategoriesQuery(int? Page , bool? SortByMain) : IRequest<List<ProductCategorySDto>>;
|
|
@ -13,12 +13,12 @@ public class GetProductCategoriesQueryHandler : IRequestHandler<GetProductCatego
|
|||
public async Task<List<ProductCategorySDto>> Handle(GetProductCategoriesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
List<ProductCategorySDto> groupCats;
|
||||
if (request.page != null)
|
||||
if (request.Page != null)
|
||||
{
|
||||
groupCats = await _repositoryWrapper.SetRepository<ProductCategory>()
|
||||
.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<GetProductCatego
|
|||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
if (request.SortByMain != null && !request.SortByMain.Value)
|
||||
return groupCats;
|
||||
|
||||
foreach (var cat in groupCats)
|
||||
cat.Children = groupCats.Where(c => c.ParentId == cat.Id).ToList();
|
||||
|
||||
var mainCats = groupCats.Where(c => c.IsMain).ToList();
|
||||
return groupCats.Where(c => c.IsMain).ToList();
|
||||
|
||||
return mainCats;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue