feat(EmallsProductResponse) , feat(EmallsProductsEndpoint)
- Add Emalls product response dtos - Add Emalls queries and add mediatr - Add Emalls enpoint to get productsrelease
parent
092d335f77
commit
f942bbb421
|
@ -21,6 +21,10 @@ public class SearchController : ICarterModule
|
|||
group.MapGet("torob", TorobAsync)
|
||||
.WithDisplayName("Get Torob Product Async")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapGet("emalls", EmallsAsync)
|
||||
.WithDisplayName("Get Emalls Product Async")
|
||||
.HasApiVersion(1.0);
|
||||
}
|
||||
|
||||
private async Task<IResult> SearchThumbAsync([FromQuery] string name, [FromServices] ISearchService searchService, CancellationToken cancellationToken)
|
||||
|
@ -44,4 +48,7 @@ public class SearchController : ICarterModule
|
|||
|
||||
private async Task<IResult> TorobAsync([FromQuery] int page, [FromServices] IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new GetTorobProductsQuery(page),cancellationToken));
|
||||
|
||||
private async Task<IResult> EmallsAsync([FromQuery] int page, [FromQuery]int? item_per_page, [FromServices] IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new GetEmallsProductsQuery(page,item_per_page??20), cancellationToken));
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
namespace Netina.Core.CoreServices.SearchServices;
|
||||
|
||||
public class GetEmallsProductQueryHandler : IRequestHandler<GetEmallsProductsQuery, EmallsResponseDto>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly SiteSettings _siteSetting;
|
||||
public GetEmallsProductQueryHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator, IOptionsSnapshot<SiteSettings> optionsSnapshot)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
_mediator = mediator;
|
||||
_siteSetting = optionsSnapshot.Value;
|
||||
}
|
||||
|
||||
public async Task<EmallsResponseDto> Handle(GetEmallsProductsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var page = request.Page;
|
||||
var productsSDto = await _repositoryWrapper.SetRepository<Product>()
|
||||
.TableNoTracking
|
||||
.OrderByDescending(p => p.ModifiedAt == DateTime.MinValue ? p.CreatedAt : p.ModifiedAt)
|
||||
.Select(p => new ProductSDto
|
||||
{
|
||||
Id = p.Id,
|
||||
BeDisplayed = p.BeDisplayed,
|
||||
IsEnable = p.IsEnable,
|
||||
Cost = p.Cost,
|
||||
CategoryId = p.CategoryId,
|
||||
BrandId = p.BrandId,
|
||||
EnglishName = p.EnglishName,
|
||||
PersianName = p.PersianName,
|
||||
Slug = p.Slug,
|
||||
|
||||
})
|
||||
.Skip(page * request.Count)
|
||||
.Take(request.Count)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
|
||||
foreach (var productSDto in productsSDto)
|
||||
await _mediator.Send(new CalculateProductDiscountCommand(productSDto), cancellationToken);
|
||||
var products = new List<EmallsProductResponseDto>();
|
||||
foreach (var product in productsSDto)
|
||||
{
|
||||
var torobProduct = new EmallsProductResponseDto
|
||||
{
|
||||
is_available = product.IsEnable,
|
||||
url = $"{_siteSetting.WebSiteUrl}/products/{product.Id}/{product.Slug}",
|
||||
id = product.Id.ToString(),
|
||||
title = product.PersianName,
|
||||
category = product.CategoryName
|
||||
};
|
||||
if (product.Cost > product.CostWithDiscount)
|
||||
{
|
||||
torobProduct.old_price = (int)product.Cost;
|
||||
torobProduct.price = (int)product.CostWithDiscount;
|
||||
}
|
||||
else
|
||||
torobProduct.price = (int)product.Cost;
|
||||
products.Add(torobProduct);
|
||||
}
|
||||
|
||||
var response = new EmallsResponseDto();
|
||||
response.item_per_page = request.Count;
|
||||
response.page_num = request.Page;
|
||||
response.total_items = (await _repositoryWrapper.SetRepository<Product>().TableNoTracking.CountAsync(cancellationToken));
|
||||
response.pages_count = response.total_items / request.Count;
|
||||
response.products = products;
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class GetTorobProductsQueryHandler : IRequestHandler<GetTorobProductsQuer
|
|||
var torobProduct = new TorobProductResponseDto
|
||||
{
|
||||
availibility = product.IsEnable,
|
||||
page_url = $"{_siteSetting.WebSiteUrl}/products/{product.Id}",
|
||||
page_url = $"{_siteSetting.WebSiteUrl}/products/{product.Id}/{product.Slug}",
|
||||
product_id = product.Id.ToString()
|
||||
};
|
||||
if (product.Cost > product.CostWithDiscount)
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
<Using Include="Netina.Domain.Dtos.LargDtos" />
|
||||
<Using Include="Netina.Domain.Dtos.RequestDtos" />
|
||||
<Using Include="Netina.Domain.Dtos.ResponseDtos" />
|
||||
<Using Include="Netina.Domain.Dtos.ResponseDtos.Emalls" />
|
||||
<Using Include="Netina.Domain.Dtos.SmallDtos" />
|
||||
<Using Include="Netina.Domain.Entities.Blogs" />
|
||||
<Using Include="Netina.Domain.Entities.Brands" />
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
using Netina.Domain.Dtos.ResponseDtos.Torob;
|
||||
using Netina.Domain.Dtos.ResponseDtos.Emalls;
|
||||
using Netina.Domain.Dtos.ResponseDtos.Torob;
|
||||
|
||||
namespace Netina.Domain.CommandQueries.Queries;
|
||||
|
||||
public sealed record GetTorobProductsQuery(int Page = 0) : IRequest<List<TorobProductResponseDto>>;
|
||||
public sealed record GetTorobProductsQuery(int Page = 0) : IRequest<List<TorobProductResponseDto>>;
|
||||
|
||||
public sealed record GetEmallsProductsQuery(int Page = 0 , int Count = 20) : IRequest<EmallsResponseDto>;
|
|
@ -0,0 +1,14 @@
|
|||
namespace Netina.Domain.Dtos.ResponseDtos.Emalls;
|
||||
|
||||
public class EmallsProductResponseDto
|
||||
{
|
||||
public string title { get; set; } = string.Empty;
|
||||
public string id { get; set; } = string.Empty;
|
||||
public int price { get; set; }
|
||||
public int? old_price { get; set; }
|
||||
public string category { get; set; }
|
||||
public string color { get; set; }
|
||||
public string guarantee { get; set; }
|
||||
public bool is_available { get; set; }
|
||||
public string url { get; set; }
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace Netina.Domain.Dtos.ResponseDtos.Emalls;
|
||||
|
||||
public class EmallsResponseDto
|
||||
{
|
||||
public List<EmallsProductResponseDto> products { get; set; } = new();
|
||||
public int total_items { get; set; }
|
||||
public int pages_count { get; set; }
|
||||
public int item_per_page { get; set; }
|
||||
public int page_num { get; set; }
|
||||
}
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="Dtos\FilterDtos\" />
|
||||
<Folder Include="Dtos\ResponseDtos\Emalls\" />
|
||||
<Folder Include="Entities\StorageFiles\" />
|
||||
<Folder Include="Models\Districts\" />
|
||||
<Folder Include="Models\Settings\" />
|
||||
|
|
Loading…
Reference in New Issue