mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 13:44:33 -04:00
Fix limit reverse issue
This commit is contained in:
parent
fbe624ca6d
commit
ef3e4dc39b
@ -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;
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user