mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-27 10:02:34 -04:00
BE Tech Debt (#4497)
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com> Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System.Linq;
|
||||
using Kavita.Common.Constants;
|
||||
using Kavita.Models.Constants;
|
||||
using Kavita.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kavita.Database.Extensions;
|
||||
|
||||
public static class ChapterQueryExtensions
|
||||
{
|
||||
public static IOrderedQueryable<Chapter> ApplyDefaultChapterOrdering(this IQueryable<Chapter> query)
|
||||
{
|
||||
return query
|
||||
.Include(c => c.Volume)
|
||||
.OrderBy(c =>
|
||||
// Priority 1: Regular volumes (not loose-leaf, not special)
|
||||
c.Volume.MinNumber == ParserConstants.LooseLeafVolumeNumber ||
|
||||
c.Volume.MinNumber == ParserConstants.SpecialVolumeNumber ? 1 : 0)
|
||||
.ThenBy(c =>
|
||||
// Priority 2: Loose leaf over specials
|
||||
c.Volume.MinNumber == ParserConstants.SpecialVolumeNumber ? 1 : 0)
|
||||
// Priority 3: Non-special chapters
|
||||
.ThenBy(c => c.IsSpecial ? 1 : 0)
|
||||
.ThenBy(c => c.Volume.MinNumber)
|
||||
.ThenBy(c => c.SortOrder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user