feat(sorting): implement ApplyOrderWithInStockPriority method for enhanced product sorting
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled

- Added ApplyOrderWithInStockPriority method to prioritize in-stock products in queries.
- Updated GetDiscountProductsQueryHandler and GetCustomerProductsByFilterQueryHandler to utilize the new sorting method, ensuring in-stock items are listed first followed by user-defined sorting or creation date.
- Improved overall query handling for product availability and sorting logic.
This commit is contained in:
masoodafar-web
2026-07-26 00:17:44 +03:30
parent d232399f43
commit ce98efdd68
3 changed files with 20 additions and 9 deletions
@@ -1,3 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Dynamic.Core;
using CMSMicroservice.Domain.Common;
@@ -16,6 +17,21 @@ public static class SortByExtensions
return source.OrderBy(NormalizeSortBy(sortBy));
}
/// <summary>
/// موجودی‌دارها اول، سپس سورت درخواستی کاربر (یا Created desc اگر SortBy خالی باشد).
/// </summary>
public static IQueryable<TSource> ApplyOrderWithInStockPriority<TSource>(
this IQueryable<TSource> source,
string? sortBy,
Expression<Func<TSource, bool>> isInStock) where TSource : BaseAuditableEntity
{
var ordered = source.OrderByDescending(isInStock);
if (string.IsNullOrWhiteSpace(sortBy))
return ordered.ThenByDescending(p => p.Created);
return ordered.ThenBy(NormalizeSortBy(sortBy));
}
/// <summary>
/// Dynamic LINQ treats "-Created" as unary minus on DateTime (invalid).
/// Project convention: leading '-' means descending sort.