Browse by Genre/Tag/Person with new metadata system for People (#3835)

Co-authored-by: Stepan Goremykin <s.goremykin@proton.me>
Co-authored-by: goremykin <goremukin@gmail.com>
Co-authored-by: Christopher <39032787+MrRobotjs@users.noreply.github.com>
Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
Joe Milazzo 2025-06-14 12:14:04 -05:00 committed by GitHub
parent 00c4712fc3
commit c52ed1f65d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
147 changed files with 6612 additions and 958 deletions

View file

@ -5,10 +5,13 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using API.Data.Misc;
using API.Data.Repositories;
using API.DTOs;
using API.DTOs.Filtering;
using API.DTOs.KavitaPlus.Manage;
using API.DTOs.Metadata.Browse;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Person;
using API.Entities.Scrobble;
using Microsoft.EntityFrameworkCore;
@ -273,6 +276,27 @@ public static class QueryableExtensions
};
}
public static IQueryable<Person> SortBy(this IQueryable<Person> query, PersonSortOptions? sort)
{
if (sort == null)
{
return query.OrderBy(p => p.Name);
}
return sort.SortField switch
{
PersonSortField.Name when sort.IsAscending => query.OrderBy(p => p.Name),
PersonSortField.Name => query.OrderByDescending(p => p.Name),
PersonSortField.SeriesCount when sort.IsAscending => query.OrderBy(p => p.SeriesMetadataPeople.Count),
PersonSortField.SeriesCount => query.OrderByDescending(p => p.SeriesMetadataPeople.Count),
PersonSortField.ChapterCount when sort.IsAscending => query.OrderBy(p => p.ChapterPeople.Count),
PersonSortField.ChapterCount => query.OrderByDescending(p => p.ChapterPeople.Count),
_ => query.OrderBy(p => p.Name)
};
}
/// <summary>
/// Performs either OrderBy or OrderByDescending on the given query based on the value of SortOptions.IsAscending.
/// </summary>