feat: add public tenant packages listing and sort order

This commit is contained in:
2025-12-11 23:57:04 +08:00
parent cf9927c078
commit c7df64f2e1
28 changed files with 731 additions and 5 deletions

View File

@@ -19,21 +19,26 @@ public sealed class EfTenantPackageRepository(TakeoutAppDbContext context) : ITe
/// <inheritdoc />
public async Task<IReadOnlyList<TenantPackage>> SearchAsync(string? keyword, bool? isActive, CancellationToken cancellationToken = default)
{
// 1. 构建基础查询
var query = context.TenantPackages.AsNoTracking();
// 2. 关键字过滤
if (!string.IsNullOrWhiteSpace(keyword))
{
var normalized = keyword.Trim();
query = query.Where(x => EF.Functions.ILike(x.Name, $"%{normalized}%") || EF.Functions.ILike(x.Description ?? string.Empty, $"%{normalized}%"));
}
// 3. 状态过滤
if (isActive.HasValue)
{
query = query.Where(x => x.IsActive == isActive.Value);
}
// 4. 排序返回
return await query
.OrderByDescending(x => x.CreatedAt)
.OrderBy(x => x.SortOrder)
.ThenByDescending(x => x.CreatedAt)
.ToListAsync(cancellationToken);
}