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, Sort<LibraryItem> sort = default,
Pagination limit = 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, where,
sort, sort,
limit); limit
);
if (!items.Any() && await _libraries.Value.GetOrDefault(id) == null) if (!items.Any() && await _libraries.Value.GetOrDefault(id) == null)
throw new ItemNotFoundException(); throw new ItemNotFoundException();
return items; return items;
@ -162,10 +164,12 @@ namespace Kyoo.Core.Controllers
Sort<LibraryItem> sort = default, Sort<LibraryItem> sort = default,
Pagination limit = 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, where,
sort, sort,
limit); limit
);
if (!items.Any() && await _libraries.Value.GetOrDefault(slug) == null) if (!items.Any() && await _libraries.Value.GetOrDefault(slug) == null)
throw new ItemNotFoundException(); throw new ItemNotFoundException();
return items; return items;

View File

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

View File

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