Fix limit reverse issue

This commit is contained in:
Zoe Roux 2023-03-13 19:29:32 +09:00
parent fbe624ca6d
commit ef3e4dc39b
3 changed files with 15 additions and 7 deletions

View File

@ -147,10 +147,12 @@ namespace Kyoo.Core.Controllers
Sort<LibraryItem> sort = default,
Pagination limit = default)
{
ICollection<LibraryItem> items = await ApplyFilters(_LibraryRelatedQuery(x => x.ID == id),
ICollection<LibraryItem> items = await ApplyFilters(
_LibraryRelatedQuery(x => x.ID == id),
where,
sort,
limit);
limit
);
if (!items.Any() && await _libraries.Value.GetOrDefault(id) == null)
throw new ItemNotFoundException();
return items;
@ -162,10 +164,12 @@ namespace Kyoo.Core.Controllers
Sort<LibraryItem> sort = default,
Pagination limit = default)
{
ICollection<LibraryItem> items = await ApplyFilters(_LibraryRelatedQuery(x => x.Slug == slug),
ICollection<LibraryItem> items = await ApplyFilters(
_LibraryRelatedQuery(x => x.Slug == slug),
where,
sort,
limit);
limit
);
if (!items.Any() && await _libraries.Value.GetOrDefault(slug) == null)
throw new ItemNotFoundException();
return items;

View File

@ -140,6 +140,8 @@ namespace Kyoo.Core.Controllers
T reference,
bool next = true)
{
sort ??= DefaultSort;
// x =>
ParameterExpression x = Expression.Parameter(typeof(T), "x");
ConstantExpression referenceC = Expression.Constant(reference, typeof(T));
@ -284,12 +286,14 @@ namespace Kyoo.Core.Controllers
if (where != null)
query = query.Where(where);
if (limit.AfterID != null)
if (limit?.AfterID != null)
{
T reference = await Get(limit.AfterID.Value);
query = query.Where(KeysetPaginatate(sort, reference, !limit.Reverse));
}
if (limit.Limit > 0)
if (limit?.Reverse == true)
query = query.Reverse();
if (limit?.Limit > 0)
query = query.Take(limit.Limit);
return await query.ToListAsync();

View File

@ -57,7 +57,7 @@ namespace Kyoo.Core
context.Result = new ConflictObjectResult(ex.Existing);
break;
case Exception ex:
_logger.LogError("Unhandled error", ex);
_logger.LogError(ex, "Unhandled error");
context.Result = new ServerErrorObjectResult(new RequestError("Internal Server Error"));
break;
}