feat : add category and brand name in filters
							parent
							
								
									04bb1c25dd
								
							
						
					
					
						commit
						bbdd8338f4
					
				|  | @ -32,24 +32,9 @@ public class BrandController : ICarterModule | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // GET:Get All Entity |     // GET:Get All Entity | ||||||
|     public async Task<IResult> GetAllAsync([FromQuery] int? page, IRepositoryWrapper repositoryWrapper, |     public async Task<IResult> GetAllAsync([FromQuery] int? page, [FromQuery]string? brandName, IMediator mediator, CancellationToken cancellationToken) | ||||||
|         CancellationToken cancellationToken) |  | ||||||
|     { |     { | ||||||
|         if (page != null) |         return TypedResults.Ok(await mediator.Send(new GetBrandsQuery(Page: page, BrandName: brandName),cancellationToken)); | ||||||
|         { |  | ||||||
|             return TypedResults.Ok(await repositoryWrapper.SetRepository<Brand>().TableNoTracking |  | ||||||
|                 .OrderByDescending(b => b.CreatedAt).Skip(page.Value * 10).Take(10) |  | ||||||
|                 .Select(BrandMapper.ProjectToSDto) |  | ||||||
|                 .ToListAsync(cancellationToken)); |  | ||||||
|         } |  | ||||||
|         else |  | ||||||
|         { |  | ||||||
| 
 |  | ||||||
|             return TypedResults.Ok(await repositoryWrapper.SetRepository<Brand>().TableNoTracking |  | ||||||
|                 .OrderByDescending(b => b.CreatedAt) |  | ||||||
|                 .Select(BrandMapper.ProjectToSDto) |  | ||||||
|                 .ToListAsync(cancellationToken)); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // GET:Get An Entity By Id |     // GET:Get An Entity By Id | ||||||
|  |  | ||||||
|  | @ -30,22 +30,22 @@ public class ProductCategoryController : ICarterModule | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // GET:Get All Entity |     // GET:Get All Entity | ||||||
|     public async Task<IResult> GetAllAsync([FromQuery]int? page, [FromQuery]bool? sortByMain,IMediator mediator, CancellationToken cancellationToken) |     public async Task<IResult> GetAllAsync([FromQuery]int? page, [FromQuery]bool? sortByMain , [FromQuery]string? categoryName,IMediator mediator, CancellationToken cancellationToken) | ||||||
|         => TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(page, sortByMain),cancellationToken)); |         => TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(Page: page,SortByMain: sortByMain , CategoryName: categoryName),cancellationToken)); | ||||||
| 
 | 
 | ||||||
|     // GET:Get An Entity By Id |     // GET:Get An Entity By Id | ||||||
|     public async Task<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken) |     public async Task<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken) | ||||||
|         => TypedResults.Ok(await mediator.Send(new GetProductCategoryQuery(id),cancellationToken)); |         => TypedResults.Ok(await mediator.Send(new GetProductCategoryQuery(id),cancellationToken)); | ||||||
| 
 | 
 | ||||||
|     // POST:Create Entity  |     // POST:Create Entity  | ||||||
|     public async Task<IResult> Post([FromBody] ProductCreateCategoryCommand request, IMediator mediator, CancellationToken cancellationToken) |     public async Task<IResult> Post([FromBody] CreateProductCategoryCommand request, IMediator mediator, CancellationToken cancellationToken) | ||||||
|         => TypedResults.Ok(await mediator.Send(request, cancellationToken)); |         => TypedResults.Ok(await mediator.Send(request, cancellationToken)); | ||||||
| 
 | 
 | ||||||
|     // PUT:Update Entity |     // PUT:Update Entity | ||||||
|     public async Task<IResult> Put([FromBody] ProductUpdateCategoryCommand request, IMediator mediator, CancellationToken cancellationToken) |     public async Task<IResult> Put([FromBody] UpdateProductCategoryCommand request, IMediator mediator, CancellationToken cancellationToken) | ||||||
|         => TypedResults.Ok(await mediator.Send(request, cancellationToken)); |         => TypedResults.Ok(await mediator.Send(request, cancellationToken)); | ||||||
| 
 | 
 | ||||||
|     // DELETE:Delete Entity |     // DELETE:Delete Entity | ||||||
|     public async Task<IResult> Delete(Guid id, IMediator mediator, CancellationToken cancellationToken) |     public async Task<IResult> Delete(Guid id, IMediator mediator, CancellationToken cancellationToken) | ||||||
|         => TypedResults.Ok(await mediator.Send(new ProductDeleteCategoryCommand(id), cancellationToken)); |         => TypedResults.Ok(await mediator.Send(new DeleteProductCategoryCommand(id), cancellationToken)); | ||||||
| } | } | ||||||
|  | @ -43,12 +43,12 @@ public class SeedController : ICarterModule | ||||||
|         if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==") |         if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==") | ||||||
|             throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized); |             throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized); | ||||||
|         Dictionary<int,Guid> categories = new Dictionary<int, Guid>(); |         Dictionary<int,Guid> categories = new Dictionary<int, Guid>(); | ||||||
|         var baseCat = await mediator.Send(new ProductCreateCategoryCommand("دسته بندی نشده", "محصولات دسته بندی نشده", default, |         var baseCat = await mediator.Send(new CreateProductCategoryCommand("دسته بندی نشده", "محصولات دسته بندی نشده", default, | ||||||
|             new List<StorageFileSDto>())); |             new List<StorageFileSDto>())); | ||||||
|         categories.Add(0,baseCat.Id); |         categories.Add(0,baseCat.Id); | ||||||
|         foreach (var requestDto in request) |         foreach (var requestDto in request) | ||||||
|         { |         { | ||||||
|             var lDto = await mediator.Send(new ProductCreateCategoryCommand(requestDto.Name,requestDto.Description,default,new List<StorageFileSDto>()), cancellationToken); |             var lDto = await mediator.Send(new CreateProductCategoryCommand(requestDto.Name,requestDto.Description,default,new List<StorageFileSDto>()), cancellationToken); | ||||||
|             categories.Add(requestDto.BaseCategoryId,lDto.Id); |             categories.Add(requestDto.BaseCategoryId,lDto.Id); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|  |  | ||||||
|  | @ -6,8 +6,8 @@ | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|     <InvariantGlobalization>true</InvariantGlobalization> |     <InvariantGlobalization>true</InvariantGlobalization> | ||||||
|     <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> |     <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||||||
|     <AssemblyVersion>0.0.0.6</AssemblyVersion> |     <AssemblyVersion>0.0.0.7</AssemblyVersion> | ||||||
|     <FileVersion>0.0.0.6</FileVersion> |     <FileVersion>0.0.0.7</FileVersion> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|  |  | ||||||
|  | @ -1,16 +1,16 @@ | ||||||
| namespace NetinaShop.Domain.CommandQueries.Commands; | namespace NetinaShop.Domain.CommandQueries.Commands; | ||||||
| 
 | 
 | ||||||
| public sealed record ProductCreateCategoryCommand( | public sealed record CreateProductCategoryCommand( | ||||||
|     string Name, |     string Name, | ||||||
|     string Description, |     string Description, | ||||||
|     Guid ParentId, |     Guid ParentId, | ||||||
|     List<StorageFileSDto> Files) : IRequest<ProductCategoryLDto>; |     List<StorageFileSDto> Files) : IRequest<ProductCategoryLDto>; | ||||||
| 
 | 
 | ||||||
| public sealed record ProductUpdateCategoryCommand( | public sealed record UpdateProductCategoryCommand( | ||||||
|     Guid Id, |     Guid Id, | ||||||
|     string Name, |     string Name, | ||||||
|     string Description, |     string Description, | ||||||
|     Guid ParentId, |     Guid ParentId, | ||||||
|     List<StorageFileSDto> Files) : IRequest<bool>; |     List<StorageFileSDto> Files) : IRequest<bool>; | ||||||
| 
 | 
 | ||||||
| public sealed record ProductDeleteCategoryCommand(Guid Id) : IRequest<bool>; | public sealed record DeleteProductCategoryCommand(Guid Id) : IRequest<bool>; | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | namespace NetinaShop.Domain.CommandQueries.Queries; | ||||||
|  | 
 | ||||||
|  | public record GetBrandQuery(Guid Id) : IRequest<BrandLDto>; | ||||||
|  | public record GetBrandsQuery(int? Page, string? BrandName) : IRequest<List<BrandSDto>>; | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| namespace NetinaShop.Domain.CommandQueries.Queries; | namespace NetinaShop.Domain.CommandQueries.Queries; | ||||||
| 
 | 
 | ||||||
| public record GetProductCategoryQuery(Guid Id) : IRequest<ProductCategoryLDto>; | public record GetProductCategoryQuery(Guid Id) : IRequest<ProductCategoryLDto>; | ||||||
| public record GetProductCategoriesQuery(int? Page , bool? SortByMain) : IRequest<List<ProductCategorySDto>>; | public record GetProductCategoriesQuery(int? Page , bool? SortByMain,string? CategoryName) : IRequest<List<ProductCategorySDto>>; | ||||||
|  | @ -0,0 +1,47 @@ | ||||||
|  | using NetinaShop.Domain.Entities.Brands; | ||||||
|  | 
 | ||||||
|  | namespace NetinaShop.Repository.Handlers.Brands; | ||||||
|  | 
 | ||||||
|  | public class GetBrandsQueryHandler : IRequestHandler<GetBrandsQuery, List<BrandSDto>> | ||||||
|  | { | ||||||
|  |     private readonly IRepositoryWrapper _repositoryWrapper; | ||||||
|  | 
 | ||||||
|  |     public GetBrandsQueryHandler(IRepositoryWrapper repositoryWrapper) | ||||||
|  |     { | ||||||
|  |         _repositoryWrapper = repositoryWrapper; | ||||||
|  |     } | ||||||
|  |     public async Task<List<BrandSDto>> Handle(GetBrandsQuery request, CancellationToken cancellationToken) | ||||||
|  |     { | ||||||
|  |         IQueryable<Brand> baseBrands; | ||||||
|  |         List<BrandSDto> brands; | ||||||
|  |         if (request.BrandName != null) | ||||||
|  |         { | ||||||
|  |             baseBrands = _repositoryWrapper.SetRepository<Brand>() | ||||||
|  |                 .TableNoTracking | ||||||
|  |                 .Where(b => b.Name.Trim().Contains(request.BrandName.Trim())) | ||||||
|  |                 .OrderByDescending(b => b.CreatedAt); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  | 
 | ||||||
|  |             baseBrands = _repositoryWrapper.SetRepository<Brand>().TableNoTracking | ||||||
|  |                 .OrderByDescending(b => b.CreatedAt); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (request.Page != null) | ||||||
|  |         { | ||||||
|  |             brands = await baseBrands.Skip(request.Page.Value * 10).Take(10) | ||||||
|  |                 .Select(BrandMapper.ProjectToSDto) | ||||||
|  |                 .ToListAsync(cancellationToken); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  | 
 | ||||||
|  |             brands = await baseBrands | ||||||
|  |                 .Select(BrandMapper.ProjectToSDto) | ||||||
|  |                 .ToListAsync(cancellationToken); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return brands; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace NetinaShop.Repository.Handlers.ProductCategories; | namespace NetinaShop.Repository.Handlers.ProductCategories; | ||||||
| 
 | 
 | ||||||
| public class CreateProductCategoryCommandHandler : IRequestHandler<ProductCreateCategoryCommand,ProductCategoryLDto> | public class CreateProductCategoryCommandHandler : IRequestHandler<CreateProductCategoryCommand,ProductCategoryLDto> | ||||||
| { | { | ||||||
|     private readonly IRepositoryWrapper _repositoryWrapper; |     private readonly IRepositoryWrapper _repositoryWrapper; | ||||||
| 
 | 
 | ||||||
|  | @ -10,7 +10,7 @@ public class CreateProductCategoryCommandHandler : IRequestHandler<ProductCreate | ||||||
|     { |     { | ||||||
|         _repositoryWrapper = repositoryWrapper; |         _repositoryWrapper = repositoryWrapper; | ||||||
|     } |     } | ||||||
|     public async Task<ProductCategoryLDto> Handle(ProductCreateCategoryCommand request, CancellationToken cancellationToken) |     public async Task<ProductCategoryLDto> Handle(CreateProductCategoryCommand request, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var ent = ProductCategory.Create(request.Name, request.Description); |         var ent = ProductCategory.Create(request.Name, request.Description); | ||||||
|         if (request.ParentId != default) |         if (request.ParentId != default) | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace NetinaShop.Repository.Handlers.ProductCategories; | namespace NetinaShop.Repository.Handlers.ProductCategories; | ||||||
| 
 | 
 | ||||||
| public class DeleteProductCategoryCommandHandler : IRequestHandler<ProductDeleteCategoryCommand, bool> | public class DeleteProductCategoryCommandHandler : IRequestHandler<DeleteProductCategoryCommand, bool> | ||||||
| { | { | ||||||
|     private readonly IRepositoryWrapper _repositoryWrapper; |     private readonly IRepositoryWrapper _repositoryWrapper; | ||||||
| 
 | 
 | ||||||
|  | @ -10,7 +10,7 @@ public class DeleteProductCategoryCommandHandler : IRequestHandler<ProductDelete | ||||||
|     { |     { | ||||||
|         _repositoryWrapper = repositoryWrapper; |         _repositoryWrapper = repositoryWrapper; | ||||||
|     } |     } | ||||||
|     public async Task<bool> Handle(ProductDeleteCategoryCommand request, CancellationToken cancellationToken) |     public async Task<bool> Handle(DeleteProductCategoryCommand request, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
|         var ent = await _repositoryWrapper.SetRepository<ProductCategory>().TableNoTracking |         var ent = await _repositoryWrapper.SetRepository<ProductCategory>().TableNoTracking | ||||||
|  |  | ||||||
|  | @ -12,20 +12,32 @@ public class GetProductCategoriesQueryHandler : IRequestHandler<GetProductCatego | ||||||
|     } |     } | ||||||
|     public async Task<List<ProductCategorySDto>> Handle(GetProductCategoriesQuery request, CancellationToken cancellationToken) |     public async Task<List<ProductCategorySDto>> Handle(GetProductCategoriesQuery request, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|  |         IQueryable<ProductCategory> basCategories; | ||||||
|         List<ProductCategorySDto> groupCats; |         List<ProductCategorySDto> groupCats; | ||||||
|  |         if (request.CategoryName != null) | ||||||
|  |         { | ||||||
|  |             basCategories = _repositoryWrapper.SetRepository<ProductCategory>() | ||||||
|  |                 .TableNoTracking | ||||||
|  |                 .Where(c => c.Name.Trim().Contains(request.CategoryName.Trim())) | ||||||
|  |                 .OrderByDescending(c => c.CreatedAt); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  | 
 | ||||||
|  |             basCategories = _repositoryWrapper.SetRepository<ProductCategory>() | ||||||
|  |                 .TableNoTracking | ||||||
|  |                 .OrderByDescending(c=>c.CreatedAt); | ||||||
|  |         } | ||||||
|         if (request.Page != null) |         if (request.Page != null) | ||||||
|         { |         { | ||||||
|             groupCats = await _repositoryWrapper.SetRepository<ProductCategory>() |             groupCats = await basCategories | ||||||
|                 .TableNoTracking |  | ||||||
|                 .OrderByDescending(c => c.CreatedAt) |  | ||||||
|                 .Skip(request.Page.Value * 15).Take(15) |                 .Skip(request.Page.Value * 15).Take(15) | ||||||
|                 .Select(CategoryMapper.ProjectToSDto) |                 .Select(CategoryMapper.ProjectToSDto) | ||||||
|                 .ToListAsync(cancellationToken); |                 .ToListAsync(cancellationToken); | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|             groupCats = await _repositoryWrapper.SetRepository<ProductCategory>() |             groupCats = await basCategories | ||||||
|                 .TableNoTracking |  | ||||||
|                 .Select(CategoryMapper.ProjectToSDto) |                 .Select(CategoryMapper.ProjectToSDto) | ||||||
|                 .ToListAsync(cancellationToken); |                 .ToListAsync(cancellationToken); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -2,11 +2,11 @@ | ||||||
| 
 | 
 | ||||||
| namespace NetinaShop.Repository.Handlers.ProductCategories; | namespace NetinaShop.Repository.Handlers.ProductCategories; | ||||||
| 
 | 
 | ||||||
| public class GetCategoryQueryHandler : IRequestHandler<GetProductCategoryQuery, ProductCategoryLDto> | public class GetProductCategoryQueryHandler : IRequestHandler<GetProductCategoryQuery, ProductCategoryLDto> | ||||||
| { | { | ||||||
|     private readonly IRepositoryWrapper _repositoryWrapper; |     private readonly IRepositoryWrapper _repositoryWrapper; | ||||||
| 
 | 
 | ||||||
|     public GetCategoryQueryHandler(IRepositoryWrapper repositoryWrapper) |     public GetProductCategoryQueryHandler(IRepositoryWrapper repositoryWrapper) | ||||||
|     { |     { | ||||||
|         _repositoryWrapper = repositoryWrapper; |         _repositoryWrapper = repositoryWrapper; | ||||||
|     } |     } | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace NetinaShop.Repository.Handlers.ProductCategories; | namespace NetinaShop.Repository.Handlers.ProductCategories; | ||||||
| 
 | 
 | ||||||
| public class UpdateProductCategoryCommandHandler : IRequestHandler<ProductUpdateCategoryCommand, bool> | public class UpdateProductCategoryCommandHandler : IRequestHandler<UpdateProductCategoryCommand, bool> | ||||||
| { | { | ||||||
|     private readonly IRepositoryWrapper _repositoryWrapper; |     private readonly IRepositoryWrapper _repositoryWrapper; | ||||||
| 
 | 
 | ||||||
|  | @ -10,7 +10,7 @@ public class UpdateProductCategoryCommandHandler : IRequestHandler<ProductUpdate | ||||||
|     { |     { | ||||||
|         _repositoryWrapper = repositoryWrapper; |         _repositoryWrapper = repositoryWrapper; | ||||||
|     } |     } | ||||||
|     public async Task<bool> Handle(ProductUpdateCategoryCommand request, CancellationToken cancellationToken) |     public async Task<bool> Handle(UpdateProductCategoryCommand request, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var ent = await _repositoryWrapper.SetRepository<ProductCategory>().TableNoTracking |         var ent = await _repositoryWrapper.SetRepository<ProductCategory>().TableNoTracking | ||||||
|             .FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken); |             .FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue