parent
a66ee7c8a2
commit
e5f62f4b14
|
@ -1,6 +1,6 @@
|
||||||
namespace Netina.Api.Controllers;
|
namespace Netina.Api.Controllers;
|
||||||
|
|
||||||
public class WebSiteController:ICarterModule
|
public class WebSiteController : ICarterModule
|
||||||
{
|
{
|
||||||
public void AddRoutes(IEndpointRouteBuilder app)
|
public void AddRoutes(IEndpointRouteBuilder app)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@ public sealed record GetProductsQuery(
|
||||||
bool? IsActive,
|
bool? IsActive,
|
||||||
bool? SpecialOffer,
|
bool? SpecialOffer,
|
||||||
int Page = 0 ,
|
int Page = 0 ,
|
||||||
string? ProductName = default,
|
string? ProductName = null,
|
||||||
QuerySortBy SortBy = QuerySortBy.None ,
|
QuerySortBy SortBy = QuerySortBy.None ,
|
||||||
Guid CategoryId = default ,
|
Guid CategoryId = default ,
|
||||||
double MinPrice = -1 ,
|
double MinPrice = -1 ,
|
||||||
|
|
|
@ -27,18 +27,7 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProd
|
||||||
if (request.IsActive != null)
|
if (request.IsActive != null)
|
||||||
products = products.Where(p => p.IsEnable == request.IsActive);
|
products = products.Where(p => p.IsEnable == request.IsActive);
|
||||||
if (request.ProductName != null)
|
if (request.ProductName != null)
|
||||||
products = products.Where(p => p.PersianName.ToLower().Trim().Contains(request.ProductName.ToLower().Trim()));
|
products = products.OrderByDescending(p => EF.Functions.TrigramsSimilarity(p.PersianName,request.ProductName));
|
||||||
if (request.CategoryId != default)
|
|
||||||
{
|
|
||||||
var cats = await _mediator.Send(new GetProductCategoryChildrenQuery(request.CategoryId), cancellationToken);
|
|
||||||
products = products.Where(p => cats.Contains(p.CategoryId));
|
|
||||||
}
|
|
||||||
if (request.BrandIds is { Length: > 0 })
|
|
||||||
products = products.Where(p => request.BrandIds.Contains(p.BrandId));
|
|
||||||
if (request.MinPrice > -1)
|
|
||||||
products = products.Where(p => p.Cost >= request.MinPrice);
|
|
||||||
if (request.MaxPrice > 0)
|
|
||||||
products = products.Where(p => p.Cost <= request.MaxPrice);
|
|
||||||
if (request.SortBy != QuerySortBy.None)
|
if (request.SortBy != QuerySortBy.None)
|
||||||
{
|
{
|
||||||
products = request.SortBy switch
|
products = request.SortBy switch
|
||||||
|
@ -55,6 +44,19 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProd
|
||||||
products = products.OrderByDescending(p => p.CreatedAt);
|
products = products.OrderByDescending(p => p.CreatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.CategoryId != default)
|
||||||
|
{
|
||||||
|
var cats = await _mediator.Send(new GetProductCategoryChildrenQuery(request.CategoryId), cancellationToken);
|
||||||
|
products = products.Where(p => cats.Contains(p.CategoryId));
|
||||||
|
}
|
||||||
|
if (request.BrandIds is { Length: > 0 })
|
||||||
|
products = products.Where(p => request.BrandIds.Contains(p.BrandId));
|
||||||
|
if (request.MinPrice > -1)
|
||||||
|
products = products.Where(p => p.Cost >= request.MinPrice);
|
||||||
|
if (request.MaxPrice > 0)
|
||||||
|
products = products.Where(p => p.Cost <= request.MaxPrice);
|
||||||
|
|
||||||
|
|
||||||
if (request.SpecialOffer != null)
|
if (request.SpecialOffer != null)
|
||||||
{
|
{
|
||||||
if (request.SpecialOffer.Value)
|
if (request.SpecialOffer.Value)
|
||||||
|
|
|
@ -29,7 +29,6 @@ public class ApplicationContext : IdentityDbContext<ApplicationUser, Application
|
||||||
|
|
||||||
builder.HasPostgresExtension("pg_trgm");
|
builder.HasPostgresExtension("pg_trgm");
|
||||||
builder.HasPostgresExtension("fuzzystrmatch");
|
builder.HasPostgresExtension("fuzzystrmatch");
|
||||||
builder.HasDbFunction(() => FuzzyStringMatchDifference(default, default));
|
|
||||||
|
|
||||||
RenameIdentityTables(builder);
|
RenameIdentityTables(builder);
|
||||||
builder.RegisterEntityTypeConfiguration(entitiesAssembly);
|
builder.RegisterEntityTypeConfiguration(entitiesAssembly);
|
||||||
|
@ -38,12 +37,6 @@ public class ApplicationContext : IdentityDbContext<ApplicationUser, Application
|
||||||
|
|
||||||
//builder.AddSequentialGuidForIdConvention();
|
//builder.AddSequentialGuidForIdConvention();
|
||||||
}
|
}
|
||||||
[DbFunction("difference", Schema = "public")]
|
|
||||||
public static int FuzzyStringMatchDifference(string source, string target)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void RenameIdentityTables(ModelBuilder builder)
|
protected void RenameIdentityTables(ModelBuilder builder)
|
||||||
{
|
{
|
||||||
builder.HasDefaultSchema("public");
|
builder.HasDefaultSchema("public");
|
||||||
|
|
Loading…
Reference in New Issue