feat(discount): add InStock filter to discount product queries and mappings
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled

- Introduced InStock property to GetDiscountProductsQuery and GetCustomerProductsByFilterQuery for filtering based on product availability.
- Updated query handlers to apply InStock filtering logic in both discount and customer product queries.
- Enhanced mapping configurations to include InStock in the response DTOs.
- Bumped Protobuf project version to reflect the addition of new features.
This commit is contained in:
masoodafar-web
2026-06-30 00:16:28 +03:30
parent 728f28f525
commit 246d893b62
8 changed files with 24 additions and 1 deletions
@@ -8,6 +8,10 @@ public class GetDiscountProductsQuery : IRequest<GetDiscountProductsResponseDto>
public PaginationState? PaginationQuery { get; set; }
public long? CategoryId { get; set; }
public string? SearchTerm { get; set; }
/// <summary>
/// true = فقط موجود (RemainingCount &gt; 0)، false = فقط ناموجود
/// </summary>
public bool? InStock { get; set; }
public bool? IsActive { get; set; }
public int? MinPrice { get; set; }
public int? MaxPrice { get; set; }
@@ -42,6 +42,11 @@ public class GetDiscountProductsQueryHandler : IRequestHandler<GetDiscountProduc
query = query.Where(p => p.IsActive == request.IsActive.Value);
}
if (request.InStock == true)
query = query.Where(p => p.RemainingCount > 0);
else if (request.InStock == false)
query = query.Where(p => p.RemainingCount <= 0);
if (request.MinPrice.HasValue)
{
query = query.Where(p => p.Price >= request.MinPrice.Value);
@@ -21,6 +21,10 @@ public class GetCustomerProductsByFilterQuery : IRequest<GetCustomerProductsByFi
public int? SaleCount { get; set; }
public int? ViewCount { get; set; }
public int? RemainingCount { get; set; }
/// <summary>
/// true = فقط موجود (RemainingCount &gt; 0)، false = فقط ناموجود
/// </summary>
public bool? InStock { get; set; }
public bool? IsActive { get; set; }
public List<long>? CategoryIds { get; set; }
}
@@ -56,6 +56,11 @@ public class GetCustomerProductsByFilterQueryHandler : IRequestHandler<GetCustom
if (request.RemainingCount.HasValue)
query = query.Where(x => x.RemainingCount == request.RemainingCount.Value);
if (request.InStock == true)
query = query.Where(x => x.RemainingCount > 0);
else if (request.InStock == false)
query = query.Where(x => x.RemainingCount <= 0);
if (request.CategoryIds != null && request.CategoryIds.Any())
query = query.Where(x => x.ProductCategories.Any(pc => request.CategoryIds.Contains(pc.CategoryId)));
@@ -3,7 +3,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.203</Version>
<Version>0.0.204</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -229,6 +229,7 @@ message GetAllProductsByFilterFilter
google.protobuf.Int32Value remaining_count = 13;
google.protobuf.Int64Value category_id = 14;
google.protobuf.BoolValue is_active = 15;
google.protobuf.BoolValue in_stock = 16;
}
message GetAllProductsByFilterResponse
{
@@ -19,6 +19,8 @@ public class DiscountProductProfile : IRegister
src => src.CategoryId != null ? src.CategoryId.Value : (long?)null)
.Map(dest => dest.IsActive,
src => src.IsActive != null ? src.IsActive.Value : (bool?)null)
.Map(dest => dest.InStock,
src => src.InStock != null ? src.InStock.Value : (bool?)null)
.Map(dest => dest.MinPrice,
src => src.MinPrice != null ? (int?)src.MinPrice.Value : null)
.Map(dest => dest.MaxPrice,
@@ -175,6 +175,7 @@ public class ProductsService : ProductsContract.ProductsContractBase
SaleCount = request.Filter?.SaleCount,
ViewCount = request.Filter?.ViewCount,
RemainingCount = request.Filter?.RemainingCount,
InStock = request.Filter?.InStock,
CategoryIds = request.Filter?.CategoryId.HasValue == true
? new List<long> { request.Filter.CategoryId.Value }
: new List<long>(),
@@ -567,6 +568,7 @@ public class ProductsService : ProductsContract.ProductsContractBase
SaleCount = request.Filter?.SaleCount,
ViewCount = request.Filter?.ViewCount,
RemainingCount = request.Filter?.RemainingCount,
InStock = request.Filter?.InStock,
CategoryIds = request.Filter?.CategoryId != null ? new List<long> { request.Filter.CategoryId.Value } : null
};