diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index 72c211ae..69302e21 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq.Expressions; +using System.Runtime.InteropServices; using System.Threading.Tasks; using JetBrains.Annotations; using Kyoo.Models; @@ -36,18 +38,80 @@ namespace Kyoo.Controllers Task AddShowLink([NotNull] Show show, Library library, Collection collection); // Get all - Task> GetLibraries(); - Task> GetCollections(); - Task> GetShows(); - Task> GetSeasons(); - Task> GetEpisodes(); - Task> GetTracks(); - Task> GetStudios(); - Task> GetPeoples(); - Task> GetGenres(); - Task> GetProviders(); + Task> GetLibraries(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetCollections(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetShows(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetSeasons(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetEpisodes(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetTracks(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetStudios(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetPeople(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetGenres(Expression> where = null, + Sort sort = default, + Pagination page = default); + Task> GetProviders(Expression> where = null, + Sort sort = default, + Pagination page = default); + + Task> GetLibraries([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetLibraries(where, new Sort(sort), page); + Task> GetCollections([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetCollections(where, new Sort(sort), page); + Task> GetShows([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetShows(where, new Sort(sort), page); + Task> GetSeasons([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetSeasons(where, new Sort(sort), page); + Task> GetEpisodes([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetEpisodes(where, new Sort(sort), page); + Task> GetTracks([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetTracks(where, new Sort(sort), page); + Task> GetStudios([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetStudios(where, new Sort(sort), page); + Task> GetPeople([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetPeople(where, new Sort(sort), page); + Task> GetGenres([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetGenres(where, new Sort(sort), page); + Task> GetProviders([Optional] Expression> where, + Expression> sort, + Pagination page = default + ) => GetProviders(where, new Sort(sort), page); - // Search + + // Search Task> SearchLibraries(string searchQuery); Task> SearchCollections(string searchQuery); Task> SearchShows(string searchQuery); diff --git a/Kyoo.Common/Controllers/IRepository.cs b/Kyoo.Common/Controllers/IRepository.cs index e401bca3..5f9fe3ae 100644 --- a/Kyoo.Common/Controllers/IRepository.cs +++ b/Kyoo.Common/Controllers/IRepository.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Runtime.InteropServices; using System.Threading.Tasks; using JetBrains.Annotations; using Kyoo.Models; @@ -42,8 +43,8 @@ namespace Kyoo.Controllers Sort sort = default, Pagination page = default); - Task> GetAll(Expression> where = null, - Expression> sort = default, + Task> GetAll([Optional] Expression> where, + Expression> sort, Pagination page = default ) => GetAll(where, new Sort(sort), page); diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 8092f5c6..6aa10c4e 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -127,54 +127,74 @@ namespace Kyoo.Controllers return _people.Get(slug); } - public Task> GetLibraries() + public Task> GetLibraries(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _libraries.GetAll(); + return _libraries.GetAll(where, sort, page); } - public Task> GetCollections() + public Task> GetCollections(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _collections.GetAll(); + return _collections.GetAll(where, sort, page); } - public Task> GetShows() + public Task> GetShows(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _shows.GetAll(); + return _shows.GetAll(where, sort, page); } - public Task> GetSeasons() + public Task> GetSeasons(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _seasons.GetAll(); + return _seasons.GetAll(where, sort, page); } - public Task> GetEpisodes() + public Task> GetEpisodes(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _episodes.GetAll(); + return _episodes.GetAll(where, sort, page); } - public Task> GetTracks() + public Task> GetTracks(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _tracks.GetAll(); + return _tracks.GetAll(where, sort, page); } - public Task> GetStudios() + public Task> GetStudios(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _studios.GetAll(); + return _studios.GetAll(where, sort, page); } - public Task> GetPeoples() + public Task> GetPeoples(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _people.GetAll(); + return _people.GetAll(where, sort, page); } - public Task> GetGenres() + public Task> GetGenres(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _genres.GetAll(); + return _genres.GetAll(where, sort, page); } - public Task> GetProviders() + public Task> GetProviders(Expression> where = null, + Sort sort = default, + Pagination page = default) { - return _providers.GetAll(); + return _providers.GetAll(where, sort, page); } public Task> GetSeasons(int showID) @@ -364,7 +384,7 @@ namespace Kyoo.Controllers return _shows.Delete(show); } - public Task DeleteSeason(Season season, IShowRepository repo) + public Task DeleteSeason(Season season) { return _seasons.Delete(season); } diff --git a/Kyoo/Controllers/Repositories/CollectionRepository.cs b/Kyoo/Controllers/Repositories/CollectionRepository.cs index e94c34b8..e9253b07 100644 --- a/Kyoo/Controllers/Repositories/CollectionRepository.cs +++ b/Kyoo/Controllers/Repositories/CollectionRepository.cs @@ -56,11 +56,19 @@ namespace Kyoo.Controllers if (where != null) query = query.Where(where); - Expression> sortOrder = sort.Key ?? (x => x.Name); - query = sort.Descendant ? query.OrderByDescending(sortOrder) : query.OrderBy(sortOrder); - - query.Where(x => x.ID ) - + Expression> sortKey = sort.Key ?? (x => x.Name); + query = sort.Descendant ? query.OrderByDescending(sortKey) : query.OrderBy(sortKey); + + if (page.AfterID != 0) + { + Collection after = await Get(page.AfterID); + object afterObj = sortKey.Compile()(after); + query = query.Where(Expression.Lambda>( + Expression.GreaterThan(sortKey, Expression.Constant(afterObj)) + )); + } + query = query.Take(page.Count <= 0 ? 20 : page.Count); + return await query.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/EpisodeRepository.cs b/Kyoo/Controllers/Repositories/EpisodeRepository.cs index e4d54134..9781e11a 100644 --- a/Kyoo/Controllers/Repositories/EpisodeRepository.cs +++ b/Kyoo/Controllers/Repositories/EpisodeRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -69,7 +70,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Episodes.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/GenreRepository.cs b/Kyoo/Controllers/Repositories/GenreRepository.cs index 9834e37e..b6ee440d 100644 --- a/Kyoo/Controllers/Repositories/GenreRepository.cs +++ b/Kyoo/Controllers/Repositories/GenreRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -46,7 +47,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Genres.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/LibraryRepository.cs b/Kyoo/Controllers/Repositories/LibraryRepository.cs index 99e15a0f..acd20b43 100644 --- a/Kyoo/Controllers/Repositories/LibraryRepository.cs +++ b/Kyoo/Controllers/Repositories/LibraryRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -48,7 +49,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Libraries.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/PeopleRepository.cs b/Kyoo/Controllers/Repositories/PeopleRepository.cs index 85664970..df5f81c6 100644 --- a/Kyoo/Controllers/Repositories/PeopleRepository.cs +++ b/Kyoo/Controllers/Repositories/PeopleRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -47,7 +48,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Peoples.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/ProviderRepository.cs b/Kyoo/Controllers/Repositories/ProviderRepository.cs index ec298411..5b946139 100644 --- a/Kyoo/Controllers/Repositories/ProviderRepository.cs +++ b/Kyoo/Controllers/Repositories/ProviderRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -46,7 +47,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Providers.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/SeasonRepository.cs b/Kyoo/Controllers/Repositories/SeasonRepository.cs index c9433c72..ef78914f 100644 --- a/Kyoo/Controllers/Repositories/SeasonRepository.cs +++ b/Kyoo/Controllers/Repositories/SeasonRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -62,7 +63,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Seasons.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/ShowRepository.cs b/Kyoo/Controllers/Repositories/ShowRepository.cs index 20bc7f67..378c724c 100644 --- a/Kyoo/Controllers/Repositories/ShowRepository.cs +++ b/Kyoo/Controllers/Repositories/ShowRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -70,7 +71,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Shows.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/StudioRepository.cs b/Kyoo/Controllers/Repositories/StudioRepository.cs index 69e93e74..4e7583cb 100644 --- a/Kyoo/Controllers/Repositories/StudioRepository.cs +++ b/Kyoo/Controllers/Repositories/StudioRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -46,7 +47,9 @@ namespace Kyoo.Controllers .ToListAsync(); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Studios.ToListAsync(); } diff --git a/Kyoo/Controllers/Repositories/TrackRepository.cs b/Kyoo/Controllers/Repositories/TrackRepository.cs index dbc54b01..c5731c0c 100644 --- a/Kyoo/Controllers/Repositories/TrackRepository.cs +++ b/Kyoo/Controllers/Repositories/TrackRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Models; using Kyoo.Models.Exceptions; @@ -49,7 +50,9 @@ namespace Kyoo.Controllers throw new InvalidOperationException("Tracks do not support the search method."); } - public async Task> GetAll() + public async Task> GetAll(Expression> where = null, + Sort sort = default, + Pagination page = default) { return await _database.Tracks.ToListAsync(); }