refactor : change cntroller and handlers
add nullable page for controllers , change handlersrelease
parent
4ebcf7538a
commit
8ea22859a1
|
@ -32,11 +32,25 @@ public class BlogCategoryController : ICarterModule
|
|||
}
|
||||
|
||||
// GET:Get All Entity
|
||||
public async Task<IResult> GetAllAsync([FromQuery] int page, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await repositoryWrapper.SetRepository<BlogCategory>().TableNoTracking
|
||||
.OrderByDescending(b => b.CreatedAt).Skip(page * 10).Take(10)
|
||||
.Select(BlogCategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken));
|
||||
public async Task<IResult> GetAllAsync([FromQuery] int? page, IRepositoryWrapper repositoryWrapper,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (page != null)
|
||||
{
|
||||
return TypedResults.Ok(await repositoryWrapper.SetRepository<BlogCategory>().TableNoTracking
|
||||
.OrderByDescending(b => b.CreatedAt).Skip(page.Value * 10).Take(10)
|
||||
.Select(BlogCategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return TypedResults.Ok(await repositoryWrapper.SetRepository<BlogCategory>().TableNoTracking
|
||||
.OrderByDescending(b => b.CreatedAt)
|
||||
.Select(BlogCategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
// GET:Get An Entity By Id
|
||||
public async Task<IResult> GetAsync(Guid id, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
|
||||
|
|
|
@ -8,8 +8,7 @@ public class BrandController : ICarterModule
|
|||
public virtual void AddRoutes(IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.NewVersionedApi("Brand")
|
||||
.MapGroup($"api/brand")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
|
||||
.MapGroup($"api/brand");
|
||||
|
||||
group.MapGet("", GetAllAsync)
|
||||
.WithDisplayName("GetAllBrands")
|
||||
|
@ -20,21 +19,38 @@ public class BrandController : ICarterModule
|
|||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("", Post)
|
||||
.HasApiVersion(1.0);
|
||||
.HasApiVersion(1.0)
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
|
||||
|
||||
group.MapPut("", Put)
|
||||
.HasApiVersion(1.0);
|
||||
.HasApiVersion(1.0)
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
|
||||
|
||||
group.MapDelete("{id}", Delete)
|
||||
.HasApiVersion(1.0);
|
||||
.HasApiVersion(1.0)
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
|
||||
}
|
||||
|
||||
// GET:Get All Entity
|
||||
public async Task<IResult> GetAllAsync([FromQuery] int page, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await repositoryWrapper.SetRepository<Brand>().TableNoTracking
|
||||
.OrderByDescending(b => b.CreatedAt).Skip(page * 10).Take(10)
|
||||
.Select(BrandMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken));
|
||||
public async Task<IResult> GetAllAsync([FromQuery] int? page, IRepositoryWrapper repositoryWrapper,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (page != null)
|
||||
{
|
||||
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
|
||||
public async Task<IResult> GetAsync(Guid id, IRepositoryWrapper repositoryWrapper, CancellationToken cancellationToken)
|
||||
|
|
|
@ -30,8 +30,8 @@ public class ProductCategoryController : ICarterModule
|
|||
}
|
||||
|
||||
// GET:Get All Entity
|
||||
public async Task<IResult> GetAllAsync(IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(),cancellationToken));
|
||||
public async Task<IResult> GetAllAsync([FromQuery]int? page,IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new GetProductCategoriesQuery(page),cancellationToken));
|
||||
|
||||
// GET:Get An Entity By Id
|
||||
public async Task<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
||||
|
|
|
@ -10,8 +10,9 @@ string Warranty,
|
|||
bool BeDisplayed,
|
||||
double Cost,
|
||||
double PackingCost,
|
||||
bool HasExpressDelivery,
|
||||
int MaxOrderCount,
|
||||
Guid BrandId,
|
||||
string BrandNames ,
|
||||
Guid CategoryId,
|
||||
List<SpecificationSDto> Specifications,
|
||||
List<StorageFileSDto> Files):IRequest<ProductLDto>;
|
||||
|
@ -27,8 +28,9 @@ public sealed record UpdateProductCommand(
|
|||
bool BeDisplayed,
|
||||
double Cost,
|
||||
double PackingCost,
|
||||
bool HasExpressDelivery,
|
||||
int MaxOrderCount,
|
||||
Guid BrandId,
|
||||
string BrandNames,
|
||||
Guid CategoryId,
|
||||
List<SpecificationSDto> Specifications,
|
||||
List<StorageFileSDto> Files) : IRequest<bool>;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetinaShop.Domain.CommandQueries.Queries;
|
||||
|
||||
public record GetProductCategoryQuery(Guid Id) : IRequest<ProductCategoryLDto>;
|
||||
public record GetProductCategoriesQuery() : IRequest<List<ProductCategorySDto>>;
|
||||
public record GetProductCategoriesQuery(int? page) : IRequest<List<ProductCategorySDto>>;
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
public partial class Product
|
||||
{
|
||||
public static Product Create(string persianName, string englishName, string summery, string expertCheck, string tags, string warranty, bool beDisplayed,
|
||||
public static Product Create(string persianName, string englishName, string summery, string expertCheck, string tags, string warranty,
|
||||
bool beDisplayed,
|
||||
double cost,
|
||||
double packingCost,
|
||||
bool hasExpressDelivery,
|
||||
|
|
|
@ -12,10 +12,23 @@ public class GetProductCategoriesQueryHandler : IRequestHandler<GetProductCatego
|
|||
}
|
||||
public async Task<List<ProductCategorySDto>> Handle(GetProductCategoriesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var groupCats = await _repositoryWrapper.SetRepository<ProductCategory>()
|
||||
.TableNoTracking
|
||||
.Select(CategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
List<ProductCategorySDto> groupCats;
|
||||
if (request.page != null)
|
||||
{
|
||||
groupCats = await _repositoryWrapper.SetRepository<ProductCategory>()
|
||||
.TableNoTracking
|
||||
.OrderByDescending(c=>c.CreatedAt)
|
||||
.Skip(request.page.Value * 15).Take(15)
|
||||
.Select(CategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupCats = await _repositoryWrapper.SetRepository<ProductCategory>()
|
||||
.TableNoTracking
|
||||
.Select(CategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
foreach (var cat in groupCats)
|
||||
cat.Children = groupCats.Where(c => c.ParentId == cat.Id).ToList();
|
||||
|
|
|
@ -12,7 +12,7 @@ public class CreateProductCommandHandler : IRequestHandler<CreateProductCommand,
|
|||
public async Task<ProductLDto> Handle(CreateProductCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var ent = Product.Create(request.PersianName, request.EnglishName, request.Summery, request.ExpertCheck,
|
||||
request.Tags, request.Warranty,request.BeDisplayed,request.Cost,request.PackingCost,0,0,0,
|
||||
request.Tags, request.Warranty,request.BeDisplayed,request.Cost,request.PackingCost,request.HasExpressDelivery,request.MaxOrderCount,
|
||||
request.BrandId,request.CategoryId);
|
||||
|
||||
foreach (var specification in request.Specifications)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using NetinaShop.Domain.Entities.Discounts;
|
||||
|
||||
namespace NetinaShop.Repository.Handlers.Products;
|
||||
namespace NetinaShop.Repository.Handlers.Products;
|
||||
|
||||
public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, List<ProductSDto>>
|
||||
{
|
||||
|
@ -33,7 +31,7 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, List<Pr
|
|||
};
|
||||
}
|
||||
|
||||
var productSDtos = await products.Skip(request.Page * 10)
|
||||
var productSDtos = await products.Skip(request.Page * 20)
|
||||
.Take(10)
|
||||
.Select(ProductMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
|
|
@ -21,9 +21,8 @@ public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand,
|
|||
request.BeDisplayed,
|
||||
request.Cost,
|
||||
request.PackingCost,
|
||||
ent.ReviewCount,
|
||||
ent.Rate,
|
||||
ent.Viewed,
|
||||
request.HasExpressDelivery,
|
||||
request.MaxOrderCount,
|
||||
request.BrandId,
|
||||
request.CategoryId);
|
||||
newEnt.Id = ent.Id;
|
||||
|
|
|
@ -106,12 +106,12 @@ try
|
|||
if (price != null && double.TryParse(price.meta_value, out double dPrice))
|
||||
product = new CreateProductCommand(wordPressPostDto.post_title, string.Empty, wordPressPostDto.post_content,
|
||||
wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, dPrice, 0,
|
||||
brandId, string.Empty, categoryId,
|
||||
false,10, brandId, categoryId,
|
||||
new List<SpecificationSDto>(), new List<StorageFileSDto>());
|
||||
else
|
||||
product = new CreateProductCommand(wordPressPostDto.post_title, string.Empty, wordPressPostDto.post_content,
|
||||
wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, 0, 0,
|
||||
brandId, string.Empty, categoryId,
|
||||
wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, 0, 0,false,10,
|
||||
brandId,categoryId,
|
||||
new List<SpecificationSDto>(), new List<StorageFileSDto>());
|
||||
|
||||
products.Add(product);
|
||||
|
|
Loading…
Reference in New Issue