Merge branch 'contains' into master

This commit is contained in:
Zoe Roux 2020-09-13 17:25:16 +02:00
commit dacfbcd3b2
26 changed files with 266 additions and 1380 deletions

View File

@ -57,245 +57,8 @@ namespace Kyoo.Controllers
Task<Genre> GetGenre(Expression<Func<Genre, bool>> where);
Task<Studio> GetStudio(Expression<Func<Studio, bool>> where);
Task<People> GetPerson(Expression<Func<People, bool>> where);
// Get by relations
Task<ICollection<Season>> GetSeasonsFromShow(int showID,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default);
Task<ICollection<Season>> GetSeasonsFromShow(int showID,
[Optional] Expression<Func<Season, bool>> where,
Expression<Func<Season, object>> sort,
Pagination limit = default
) => GetSeasonsFromShow(showID, where, new Sort<Season>(sort), limit);
Task<ICollection<Season>> GetSeasonsFromShow(string showSlug,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default);
Task<ICollection<Season>> GetSeasonsFromShow(string showSlug,
[Optional] Expression<Func<Season, bool>> where,
Expression<Func<Season, object>> sort,
Pagination limit = default
) => GetSeasonsFromShow(showSlug, where, new Sort<Season>(sort), limit);
Task<ICollection<Episode>> GetEpisodesFromShow(int showID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetEpisodesFromShow(int showID,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetEpisodesFromShow(showID, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetEpisodesFromShow(string showSlug,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetEpisodesFromShow(string showSlug,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetEpisodesFromShow(showSlug, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetEpisodesFromSeason(int seasonID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetEpisodesFromSeason(int seasonID,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetEpisodesFromSeason(seasonID, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetEpisodesFromSeason(int showID,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetEpisodesFromSeason(int showID,
int seasonNumber,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetEpisodesFromSeason(showID, seasonNumber, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetEpisodesFromSeason(string showSlug,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetEpisodesFromSeason(string showSlug,
int seasonNumber,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetEpisodesFromSeason(showSlug, seasonNumber, where, new Sort<Episode>(sort), limit);
Task<ICollection<PeopleRole>> GetPeopleFromShow(int showID,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default);
Task<ICollection<PeopleRole>> GetPeopleFromShow(int showID,
[Optional] Expression<Func<PeopleRole, bool>> where,
Expression<Func<PeopleRole, object>> sort,
Pagination limit = default
) => GetPeopleFromShow(showID, where, new Sort<PeopleRole>(sort), limit);
Task<ICollection<PeopleRole>> GetPeopleFromShow(string showSlug,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default);
Task<ICollection<PeopleRole>> GetPeopleFromShow(string showSlug,
[Optional] Expression<Func<PeopleRole, bool>> where,
Expression<Func<PeopleRole, object>> sort,
Pagination limit = default
) => GetPeopleFromShow(showSlug, where, new Sort<PeopleRole>(sort), limit);
Task<ICollection<Genre>> GetGenresFromShow(int showID,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default);
Task<ICollection<Genre>> GetGenresFromShow(int showID,
[Optional] Expression<Func<Genre, bool>> where,
Expression<Func<Genre, object>> sort,
Pagination limit = default
) => GetGenresFromShow(showID, where, new Sort<Genre>(sort), limit);
Task<ICollection<Genre>> GetGenresFromShow(string showSlug,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default);
Task<ICollection<Genre>> GetGenresFromShow(string showSlug,
[Optional] Expression<Func<Genre, bool>> where,
Expression<Func<Genre, object>> sort,
Pagination limit = default
) => GetGenresFromShow(showSlug, where, new Sort<Genre>(sort), limit);
Task<ICollection<Track>> GetTracksFromEpisode(int episodeID,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetTracksFromEpisode(int episodeID,
[Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
) => GetTracksFromEpisode(episodeID, where, new Sort<Track>(sort), limit);
Task<ICollection<Track>> GetTracksFromEpisode(int showID,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetTracksFromEpisode(int showID,
int seasonNumber,
int episodeNumber,
[Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
) => GetTracksFromEpisode(showID, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
Task<ICollection<Track>> GetTracksFromEpisode(string showSlug,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetTracksFromEpisode(string showSlug,
int seasonNumber,
int episodeNumber,
[Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
) => GetTracksFromEpisode(showSlug, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
Task<Studio> GetStudioFromShow(int showID);
Task<Studio> GetStudioFromShow(string showSlug);
Task<Show> GetShowFromSeason(int seasonID);
Task<Show> GetShowFromEpisode(int episodeID);
Task<Season> GetSeasonFromEpisode(int episodeID);
Task<ICollection<Library>> GetLibrariesFromShow(int showID,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetLibrariesFromShow(int showID,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetLibrariesFromShow(showID, where, new Sort<Library>(sort), limit);
Task<ICollection<Library>> GetLibrariesFromShow(string showSlug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetLibrariesFromShow(string showSlug,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetLibrariesFromShow(showSlug, where, new Sort<Library>(sort), limit);
Task<ICollection<Collection>> GetCollectionsFromShow(int showID,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetCollectionsFromShow(int showID,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetCollectionsFromShow(showID, where, new Sort<Collection>(sort), limit);
Task<ICollection<Collection>> GetCollectionsFromShow(string showSlug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetCollectionsFromShow(string showSlug,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetCollectionsFromShow(showSlug, where, new Sort<Collection>(sort), limit);
Task<ICollection<Show>> GetShowsFromLibrary(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetShowsFromLibrary(int id,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetShowsFromLibrary(id, where, new Sort<Show>(sort), limit);
Task<ICollection<Show>> GetShowsFromLibrary(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetShowsFromLibrary(string slug,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetShowsFromLibrary(slug, where, new Sort<Show>(sort), limit);
Task<ICollection<Collection>> GetCollectionsFromLibrary(int id,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetCollectionsFromLibrary(int id,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetCollectionsFromLibrary(id, where, new Sort<Collection>(sort), limit);
Task<ICollection<Collection>> GetCollectionsFromLibrary(string showSlug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetCollectionsFromLibrary(string showSlug,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetCollectionsFromLibrary(showSlug, where, new Sort<Collection>(sort), limit);
// Library Items relations
Task<ICollection<LibraryItem>> GetItemsFromLibrary(int id,
Expression<Func<LibraryItem, bool>> where = null,
Sort<LibraryItem> sort = default,
@ -316,46 +79,28 @@ namespace Kyoo.Controllers
Pagination limit = default
) => GetItemsFromLibrary(librarySlug, where, new Sort<LibraryItem>(sort), limit);
Task<ICollection<Show>> GetShowsFromCollection(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
// People Role relations
Task<ICollection<PeopleRole>> GetPeopleFromShow(int showID,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetShowsFromCollection(int id,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Task<ICollection<PeopleRole>> GetPeopleFromShow(int showID,
[Optional] Expression<Func<PeopleRole, bool>> where,
Expression<Func<PeopleRole, object>> sort,
Pagination limit = default
) => GetShowsFromCollection(id, where, new Sort<Show>(sort), limit);
) => GetPeopleFromShow(showID, where, new Sort<PeopleRole>(sort), limit);
Task<ICollection<Show>> GetShowsFromCollection(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Task<ICollection<PeopleRole>> GetPeopleFromShow(string showSlug,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetShowsFromCollection(string slug,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Task<ICollection<PeopleRole>> GetPeopleFromShow(string showSlug,
[Optional] Expression<Func<PeopleRole, bool>> where,
Expression<Func<PeopleRole, object>> sort,
Pagination limit = default
) => GetShowsFromCollection(slug, where, new Sort<Show>(sort), limit);
Task<ICollection<Library>> GetLibrariesFromCollection(int id,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetLibrariesFromCollection(int id,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetLibrariesFromCollection(id, where, new Sort<Library>(sort), limit);
Task<ICollection<Library>> GetLibrariesFromCollection(string slug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetLibrariesFromCollection(string slug,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetLibrariesFromCollection(slug, where, new Sort<Library>(sort), limit);
) => GetPeopleFromShow(showSlug, where, new Sort<PeopleRole>(sort), limit);
// Show Role relations
Task<ICollection<ShowRole>> GetRolesFromPeople(int showID,
Expression<Func<ShowRole, bool>> where = null,
Sort<ShowRole> sort = default,
@ -376,7 +121,6 @@ namespace Kyoo.Controllers
Pagination limit = default
) => GetRolesFromPeople(showSlug, where, new Sort<ShowRole>(sort), limit);
// Helpers
Task AddShowLink(int showID, int? libraryID, int? collectionID);
Task AddShowLink([NotNull] Show show, Library library, Collection collection);
@ -391,10 +135,10 @@ namespace Kyoo.Controllers
Task<ICollection<Show>> GetShows(Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Season>> GetSeasonsFromShow(Expression<Func<Season, bool>> where = null,
Task<ICollection<Season>> GetSeasons(Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetEpisodesFromShow(Expression<Func<Episode, bool>> where = null,
Task<ICollection<Episode>> GetEpisodes(Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetTracks(Expression<Func<Track, bool>> where = null,
@ -425,14 +169,6 @@ namespace Kyoo.Controllers
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetShows(where, new Sort<Show>(sort), limit);
Task<ICollection<Season>> GetSeasonsFromShow([Optional] Expression<Func<Season, bool>> where,
Expression<Func<Season, object>> sort,
Pagination limit = default
) => GetSeasonsFromShow(where, new Sort<Season>(sort), limit);
Task<ICollection<Episode>> GetEpisodesFromShow([Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetEpisodesFromShow(where, new Sort<Episode>(sort), limit);
Task<ICollection<Track>> GetTracks([Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
@ -455,7 +191,7 @@ namespace Kyoo.Controllers
) => GetProviders(where, new Sort<ProviderID>(sort), limit);
// Search
// Search
Task<ICollection<Library>> SearchLibraries(string searchQuery);
Task<ICollection<Collection>> SearchCollections(string searchQuery);
Task<ICollection<Show>> SearchShows(string searchQuery);

View File

@ -30,7 +30,7 @@ namespace Kyoo.Controllers
public Sort(Expression<Func<T, object>> key, bool descendant = false)
{
Key = key;
Key = ExpressionRewrite.Rewrite<Func<T, object>>(key);
Descendant = descendant;
if (Key == null ||
@ -58,6 +58,7 @@ namespace Kyoo.Controllers
Key = property.Type.IsValueType
? Expression.Lambda<Func<T, object>>(Expression.Convert(property, typeof(object)), param)
: Expression.Lambda<Func<T, object>>(property, param);
Key = ExpressionRewrite.Rewrite<Func<T, object>>(Key);
Descendant = order switch
{
@ -109,49 +110,6 @@ namespace Kyoo.Controllers
public interface IShowRepository : IRepository<Show>
{
Task AddShowLink(int showID, int? libraryID, int? collectionID);
Task<ICollection<Show>> GetFromLibrary(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetFromLibrary(int id,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetFromLibrary(id, where, new Sort<Show>(sort), limit);
Task<ICollection<Show>> GetFromLibrary(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetFromLibrary(string slug,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetFromLibrary(slug, where, new Sort<Show>(sort), limit);
Task<ICollection<Show>> GetFromCollection(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetFromCollection(int id,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetFromCollection(id, where, new Sort<Show>(sort), limit);
Task<ICollection<Show>> GetFromCollection(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default);
Task<ICollection<Show>> GetFromCollection(string slug,
[Optional] Expression<Func<Show, bool>> where,
Expression<Func<Show, object>> sort,
Pagination limit = default
) => GetFromCollection(slug, where, new Sort<Show>(sort), limit);
Task<Show> GetFromSeason(int seasonID);
Task<Show> GetFromEpisode(int episodeID);
}
public interface ISeasonRepository : IRepository<Season>
@ -159,28 +117,6 @@ namespace Kyoo.Controllers
Task<Season> Get(int showID, int seasonNumber);
Task<Season> Get(string showSlug, int seasonNumber);
Task Delete(string showSlug, int seasonNumber);
Task<ICollection<Season>> GetFromShow(int showID,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default);
Task<ICollection<Season>> GetFromShow(int showID,
[Optional] Expression<Func<Season, bool>> where,
Expression<Func<Season, object>> sort,
Pagination limit = default
) => GetFromShow(showID, where, new Sort<Season>(sort), limit);
Task<ICollection<Season>> GetFromShow(string showSlug,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default);
Task<ICollection<Season>> GetFromShow(string showSlug,
[Optional] Expression<Func<Season, bool>> where,
Expression<Func<Season, object>> sort,
Pagination limit = default
) => GetFromShow(showSlug, where, new Sort<Season>(sort), limit);
Task<Season> GetFromEpisode(int episodeID);
}
public interface IEpisodeRepository : IRepository<Episode>
@ -191,143 +127,10 @@ namespace Kyoo.Controllers
Task<Episode> GetAbsolute(int showID, int absoluteNumber);
Task<Episode> GetAbsolute(string showSlug, int absoluteNumber);
Task Delete(string showSlug, int seasonNumber, int episodeNumber);
Task<ICollection<Episode>> GetFromShow(int showID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetFromShow(int showID,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetFromShow(showID, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetFromShow(string showSlug,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetFromShow(string showSlug,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetFromShow(showSlug, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetFromSeason(int seasonID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetFromSeason(int seasonID,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetFromSeason(seasonID, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetFromSeason(int showID,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetFromSeason(int showID,
int seasonNumber,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetFromSeason(showID, seasonNumber, where, new Sort<Episode>(sort), limit);
Task<ICollection<Episode>> GetFromSeason(string showSlug,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default);
Task<ICollection<Episode>> GetFromSeason(string showSlug,
int seasonNumber,
[Optional] Expression<Func<Episode, bool>> where,
Expression<Func<Episode, object>> sort,
Pagination limit = default
) => GetFromSeason(showSlug, seasonNumber, where, new Sort<Episode>(sort), limit);
}
public interface ITrackRepository : IRepository<Track>
{
Task<ICollection<Track>> GetFromEpisode(int episodeID,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetFromEpisode(int episodeID,
[Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
) => GetFromEpisode(episodeID, where, new Sort<Track>(sort), limit);
Task<ICollection<Track>> GetFromEpisode(int showID,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetFromEpisode(int showID,
int seasonNumber,
int episodeNumber,
[Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
) => GetFromEpisode(showID, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
Task<ICollection<Track>> GetFromEpisode(string showSlug,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default);
Task<ICollection<Track>> GetFromEpisode(string showSlug,
int seasonNumber,
int episodeNumber,
[Optional] Expression<Func<Track, bool>> where,
Expression<Func<Track, object>> sort,
Pagination limit = default
) => GetFromEpisode(showSlug, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
}
public interface ILibraryRepository : IRepository<Library>
{
Task<ICollection<Library>> GetFromShow(int showID,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetFromShow(int showID,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetFromShow(showID, where, new Sort<Library>(sort), limit);
Task<ICollection<Library>> GetFromShow(string showSlug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetFromShow(string showSlug,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetFromShow(showSlug, where, new Sort<Library>(sort), limit);
Task<ICollection<Library>> GetFromCollection(int id,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetFromCollection(int id,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetFromCollection(id, where, new Sort<Library>(sort), limit);
Task<ICollection<Library>> GetFromCollection(string slug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default);
Task<ICollection<Library>> GetFromCollection(string slug,
[Optional] Expression<Func<Library, bool>> where,
Expression<Func<Library, object>> sort,
Pagination limit = default
) => GetFromCollection(slug, where, new Sort<Library>(sort), limit);
}
public interface ITrackRepository : IRepository<Track> { }
public interface ILibraryRepository : IRepository<Library> { }
public interface ILibraryItemRepository : IRepository<LibraryItem>
{
@ -352,79 +155,11 @@ namespace Kyoo.Controllers
Expression<Func<LibraryItem, object>> sort,
Pagination limit = default
) => GetFromLibrary(librarySlug, where, new Sort<LibraryItem>(sort), limit);
}
public interface ICollectionRepository : IRepository<Collection>
{
Task<ICollection<Collection>> GetFromShow(int showID,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetFromShow(int showID,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetFromShow(showID, where, new Sort<Collection>(sort), limit);
}
Task<ICollection<Collection>> GetFromShow(string showSlug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetFromShow(string showSlug,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetFromShow(showSlug, where, new Sort<Collection>(sort), limit);
Task<ICollection<Collection>> GetFromLibrary(int id,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetFromLibrary(int id,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetFromLibrary(id, where, new Sort<Collection>(sort), limit);
Task<ICollection<Collection>> GetFromLibrary(string slug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default);
Task<ICollection<Collection>> GetFromLibrary(string slug,
[Optional] Expression<Func<Collection, bool>> where,
Expression<Func<Collection, object>> sort,
Pagination limit = default
) => GetFromLibrary(slug, where, new Sort<Collection>(sort), limit);
}
public interface IGenreRepository : IRepository<Genre>
{
Task<ICollection<Genre>> GetFromShow(int showID,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default);
Task<ICollection<Genre>> GetFromShow(int showID,
[Optional] Expression<Func<Genre, bool>> where,
Expression<Func<Genre, object>> sort,
Pagination limit = default
) => GetFromShow(showID, where, new Sort<Genre>(sort), limit);
Task<ICollection<Genre>> GetFromShow(string showSlug,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default);
Task<ICollection<Genre>> GetFromShow(string showSlug,
[Optional] Expression<Func<Genre, bool>> where,
Expression<Func<Genre, object>> sort,
Pagination limit = default
) => GetFromShow(showSlug, where, new Sort<Genre>(sort), limit);
}
public interface IStudioRepository : IRepository<Studio>
{
Task<Studio> GetFromShow(int showID);
Task<Studio> GetFromShow(string showSlug);
}
public interface ICollectionRepository : IRepository<Collection> { }
public interface IGenreRepository : IRepository<Genre> { }
public interface IStudioRepository : IRepository<Studio> { }
public interface IPeopleRepository : IRepository<People>
{
@ -468,5 +203,6 @@ namespace Kyoo.Controllers
Pagination limit = default
) => GetFromPeople(showSlug, where, new Sort<ShowRole>(sort), limit);
}
public interface IProviderRepository : IRepository<ProviderID> {}
}

View File

@ -241,18 +241,18 @@ namespace Kyoo.Controllers
return ShowRepository.GetAll(where, sort, limit);
}
public Task<ICollection<Season>> GetSeasonsFromShow(Expression<Func<Season, bool>> where = null,
public Task<ICollection<Season>> GetSeasons(Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination page = default)
Pagination limit = default)
{
return SeasonRepository.GetAll(where, sort, page);
return SeasonRepository.GetAll(where, sort, limit);
}
public Task<ICollection<Episode>> GetEpisodesFromShow(Expression<Func<Episode, bool>> where = null,
public Task<ICollection<Episode>> GetEpisodes(Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination page = default)
Pagination limit = default)
{
return EpisodeRepository.GetAll(where, sort, page);
return EpisodeRepository.GetAll(where, sort, limit);
}
public Task<ICollection<Track>> GetTracks(Expression<Func<Track, bool>> where = null,
@ -290,213 +290,6 @@ namespace Kyoo.Controllers
return ProviderRepository.GetAll(where, sort, page);
}
public Task<ICollection<Season>> GetSeasonsFromShow(int showID,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default)
{
return SeasonRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<Season>> GetSeasonsFromShow(string showSlug,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default)
{
return SeasonRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<Episode>> GetEpisodesFromShow(int showID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
return EpisodeRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<Episode>> GetEpisodesFromShow(string showSlug,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
return EpisodeRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<Episode>> GetEpisodesFromSeason(int seasonID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
return EpisodeRepository.GetFromSeason(seasonID, where, sort, limit);
}
public Task<ICollection<Episode>> GetEpisodesFromSeason(int showID,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
return EpisodeRepository.GetFromSeason(showID, seasonNumber, where, sort, limit);
}
public Task<ICollection<Episode>> GetEpisodesFromSeason(string showSlug,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
return EpisodeRepository.GetFromSeason(showSlug, seasonNumber, where, sort, limit);
}
public Task<ICollection<PeopleRole>> GetPeopleFromShow(int showID,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
return PeopleRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<PeopleRole>> GetPeopleFromShow(string showSlug,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
return PeopleRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<Genre>> GetGenresFromShow(int showID,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default)
{
return GenreRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<Genre>> GetGenresFromShow(string showSlug,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default)
{
return GenreRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<Track>> GetTracksFromEpisode(int episodeID,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default)
{
return TrackRepository.GetFromEpisode(episodeID, where, sort, limit);
}
public Task<ICollection<Track>> GetTracksFromEpisode(int showID,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default)
{
return TrackRepository.GetFromEpisode(showID, seasonNumber, episodeNumber, where, sort, limit);
}
public Task<ICollection<Track>> GetTracksFromEpisode(string showSlug,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default)
{
return TrackRepository.GetFromEpisode(showSlug, seasonNumber, episodeNumber, where, sort, limit);
}
public Task<Studio> GetStudioFromShow(int showID)
{
return StudioRepository.GetFromShow(showID);
}
public Task<Studio> GetStudioFromShow(string showSlug)
{
return StudioRepository.GetFromShow(showSlug);
}
public Task<Show> GetShowFromSeason(int seasonID)
{
return ShowRepository.GetFromSeason(seasonID);
}
public Task<Show> GetShowFromEpisode(int episodeID)
{
return ShowRepository.GetFromEpisode(episodeID);
}
public Task<Season> GetSeasonFromEpisode(int episodeID)
{
return SeasonRepository.GetFromEpisode(episodeID);
}
public Task<ICollection<Library>> GetLibrariesFromShow(int showID,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
return LibraryRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<Library>> GetLibrariesFromShow(string showSlug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
return LibraryRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<Collection>> GetCollectionsFromShow(int showID,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
return CollectionRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<Collection>> GetCollectionsFromShow(string showSlug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
return CollectionRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<Show>> GetShowsFromLibrary(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
return ShowRepository.GetFromLibrary(id, where, sort, limit);
}
public Task<ICollection<Show>> GetShowsFromLibrary(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
return ShowRepository.GetFromLibrary(slug, where, sort, limit);
}
public Task<ICollection<Collection>> GetCollectionsFromLibrary(int id,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
return CollectionRepository.GetFromLibrary(id, where, sort, limit);
}
public Task<ICollection<Collection>> GetCollectionsFromLibrary(string slug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
return CollectionRepository.GetFromLibrary(slug, where, sort, limit);
}
public Task<ICollection<LibraryItem>> GetItemsFromLibrary(int id,
Expression<Func<LibraryItem, bool>> where = null,
Sort<LibraryItem> sort = default,
@ -512,37 +305,21 @@ namespace Kyoo.Controllers
{
return LibraryItemRepository.GetFromLibrary(librarySlug, where, sort, limit);
}
public Task<ICollection<Show>> GetShowsFromCollection(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
public Task<ICollection<PeopleRole>> GetPeopleFromShow(int showID,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
return ShowRepository.GetFromCollection(id, where, sort, limit);
}
public Task<ICollection<Show>> GetShowsFromCollection(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
return ShowRepository.GetFromCollection(slug, where, sort, limit);
return PeopleRepository.GetFromShow(showID, where, sort, limit);
}
public Task<ICollection<Library>> GetLibrariesFromCollection(int id,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
public Task<ICollection<PeopleRole>> GetPeopleFromShow(string showSlug,
Expression<Func<PeopleRole, bool>> where = null,
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
return LibraryRepository.GetFromCollection(id, where, sort, limit);
}
public Task<ICollection<Library>> GetLibrariesFromCollection(string slug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
return LibraryRepository.GetFromCollection(slug, where, sort, limit);
return PeopleRepository.GetFromShow(showSlug, where, sort, limit);
}
public Task<ICollection<ShowRole>> GetRolesFromPeople(int id,

View File

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Kyoo
{
public class ExpressionRewriteAttribute : Attribute
{
public string Link { get; }
public string Inner { get; }
public ExpressionRewriteAttribute(string link, string inner = null)
{
Link = link;
Inner = inner;
}
}
public class ExpressionRewrite : ExpressionVisitor
{
private string _inner;
private readonly List<(string inner, ParameterExpression param, ParameterExpression newParam)> _innerRewrites;
private ExpressionRewrite()
{
_innerRewrites = new List<(string, ParameterExpression, ParameterExpression)>();
}
public static Expression Rewrite(Expression expression)
{
return new ExpressionRewrite().Visit(expression);
}
public static Expression<T> Rewrite<T>(Expression expression) where T : Delegate
{
return (Expression<T>)new ExpressionRewrite().Visit(expression);
}
protected override Expression VisitMember(MemberExpression node)
{
(string inner, _, ParameterExpression p) = _innerRewrites.FirstOrDefault(x => x.param == node.Expression);
if (inner != null)
{
Expression param = p;
foreach (string accessor in inner.Split('.'))
param = Expression.Property(param, accessor);
node = Expression.Property(param, node.Member.Name);
}
// Can't use node.Member directly because we want to support attribute override
MemberInfo member = node.Expression.Type.GetProperty(node.Member.Name) ?? node.Member;
ExpressionRewriteAttribute attr = member!.GetCustomAttribute<ExpressionRewriteAttribute>();
if (attr == null)
return base.VisitMember(node);
Expression property = node.Expression;
foreach (string child in attr.Link.Split('.'))
property = Expression.Property(property, child);
if (property is MemberExpression expr)
Visit(expr.Expression);
_inner = attr.Inner;
return property;
}
protected override Expression VisitLambda<T>(Expression<T> node)
{
(_, ParameterExpression oldParam, ParameterExpression param) = _innerRewrites
.FirstOrDefault(x => node.Parameters.Any(y => y == x.param));
if (param == null)
return base.VisitLambda(node);
ParameterExpression[] newParams = node.Parameters.Where(x => x != oldParam).Append(param).ToArray();
return Expression.Lambda(Visit(node.Body)!, newParams);
}
protected override Expression VisitMethodCall(MethodCallExpression node)
{
int count = node.Arguments.Count;
if (node.Object != null)
count++;
if (count != 2)
return base.VisitMethodCall(node);
Expression instance = node.Object ?? node.Arguments.First();
Expression argument = node.Object != null
? node.Arguments.First()
: node.Arguments[1];
Type oldType = instance.Type;
instance = Visit(instance);
if (instance!.Type == oldType)
return base.VisitMethodCall(node);
if (_inner != null && argument is LambdaExpression lambda)
{
// TODO this type handler will usually work with IEnumerable & others but won't work with everything.
Type type = oldType.GetGenericArguments().First();
ParameterExpression oldParam = lambda.Parameters.FirstOrDefault(x => x.Type == type);
if (oldParam != null)
{
Type newType = instance.Type.GetGenericArguments().First();
ParameterExpression newParam = Expression.Parameter(newType, oldParam.Name);
_innerRewrites.Add((_inner, oldParam, newParam));
}
}
argument = Visit(argument);
// TODO this method handler may not work for some methods (ex: method taking a Fun<> method won't have good generic arguments)
MethodInfo method = node.Method.IsGenericMethod
? node.Method.GetGenericMethodDefinition().MakeGenericMethod(instance.Type.GetGenericArguments())
: node.Method;
return node.Object != null
? Expression.Call(instance, method!, argument)
: Expression.Call(null, method!, instance, argument!);
}
}
}

View File

@ -11,24 +11,28 @@ namespace Kyoo.Models
[JsonIgnore] public int PeopleID { get; set; }
[JsonIgnore] public virtual People People { get; set; }
[ExpressionRewrite(nameof(People) + "." + nameof(Models.People.Slug))]
public string Slug
{
get => People.Slug;
set => People.Slug = value;
}
[ExpressionRewrite(nameof(People) + "."+ nameof(Models.People.Name))]
public string Name
{
get => People.Name;
set => People.Name = value;
}
[ExpressionRewrite(nameof(People) + "."+ nameof(Models.People.Poster))]
public string Poster
{
get => People.Poster;
set => People.Poster = value;
}
[ExpressionRewrite(nameof(People) + "."+ nameof(Models.People.ExternalIDs))]
public IEnumerable<MetadataID> ExternalIDs
{
get => People.ExternalIDs;

View File

@ -309,12 +309,14 @@ namespace Kyoo
public static Expression<T> Convert<T>([CanBeNull] this Expression expr)
where T : Delegate
{
return expr switch
Expression<T> e = expr switch
{
null => null,
LambdaExpression lambda => new ExpressionConverter<T>(lambda).VisitAndConvert(),
_ => throw new ArgumentException("Can't convert a non lambda.")
};
return ExpressionRewrite.Rewrite<T>(e);
}
private class ExpressionConverter<TTo> : ExpressionVisitor
@ -342,26 +344,17 @@ namespace Kyoo
}
internal Expression<TTo> VisitAndConvert()
{
return (Expression<TTo>)RunGenericMethod(
this,
"VisitLambda",
_expression.GetType().GetGenericArguments().First(),
_expression);
}
protected override Expression VisitLambda<T>(Expression<T> node)
{
Type returnType = _expression.Type.GetGenericArguments().Last();
Expression body = node.ReturnType == returnType
? Visit(node.Body)
: Expression.Convert(Visit(node.Body)!, returnType);
Expression body = _expression.ReturnType == returnType
? Visit(_expression.Body)
: Expression.Convert(Visit(_expression.Body)!, returnType);
return Expression.Lambda<TTo>(body!, _newParams);
}
protected override Expression VisitParameter(ParameterExpression node)
{
return _newParams.First(x => x.Name == node.Name);
return _newParams.FirstOrDefault(x => x.Name == node.Name) ?? node;
}
}
}

View File

@ -24,9 +24,14 @@ namespace Kyoo.CommonApi
Expression<Func<T, bool>> defaultWhere = null)
{
if (where == null || where.Count == 0)
return defaultWhere;
ParameterExpression param = Expression.Parameter(typeof(T));
{
if (defaultWhere == null)
return null;
Expression body = ExpressionRewrite.Rewrite(defaultWhere.Body);
return Expression.Lambda<Func<T, bool>>(body, defaultWhere.Parameters.First());
}
ParameterExpression param = defaultWhere?.Parameters.First() ?? Expression.Parameter(typeof(T));
Expression expression = defaultWhere?.Body;
foreach ((string key, string desired) in where)
@ -71,8 +76,9 @@ namespace Kyoo.CommonApi
else
expression = condition;
}
return Expression.Lambda<Func<T, bool>>(expression!, param);
expression = ExpressionRewrite.Rewrite(expression);
return Expression.Lambda<Func<T, bool>>(expression, param);
}
private static Expression ContainsResourceExpression(MemberExpression xProperty, string value)

View File

@ -4,9 +4,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@ -14,15 +12,11 @@ namespace Kyoo.Controllers
{
private bool _disposed;
private readonly DatabaseContext _database;
private readonly Lazy<IShowRepository> _shows;
private readonly Lazy<ILibraryRepository> _libraries;
protected override Expression<Func<CollectionDE, object>> DefaultSort => x => x.Name;
public CollectionRepository(DatabaseContext database, IServiceProvider services) : base(database)
public CollectionRepository(DatabaseContext database) : base(database)
{
_database = database;
_shows = new Lazy<IShowRepository>(services.GetRequiredService<IShowRepository>);
_libraries = new Lazy<ILibraryRepository>(services.GetRequiredService<ILibraryRepository>);
}
public override void Dispose()
@ -31,10 +25,6 @@ namespace Kyoo.Controllers
return;
_disposed = true;
_database.Dispose();
if (_shows.IsValueCreated)
_shows.Value.Dispose();
if (_libraries.IsValueCreated)
_libraries.Value.Dispose();
}
public override async ValueTask DisposeAsync()
@ -43,12 +33,8 @@ namespace Kyoo.Controllers
return;
_disposed = true;
await _database.DisposeAsync();
if (_shows.IsValueCreated)
await _shows.Value.DisposeAsync();
if (_libraries.IsValueCreated)
await _libraries.Value.DisposeAsync();
}
public override async Task<ICollection<Collection>> Search(string query)
{
return await _database.Collections
@ -79,71 +65,5 @@ namespace Kyoo.Controllers
_database.Entry(link).State = EntityState.Deleted;
await _database.SaveChangesAsync();
}
public async Task<ICollection<Collection>> GetFromShow(int showID,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
ICollection<Collection> collections = await ApplyFilters(_database.CollectionLinks
.Where(x => x.ShowID == showID)
.Select(x => (CollectionDE)x.Collection),
where,
sort,
limit);
if (!collections.Any() & await _shows.Value.Get(showID) == null)
throw new ItemNotFound();
return collections;
}
public async Task<ICollection<Collection>> GetFromShow(string showSlug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
ICollection<Collection> collections = await ApplyFilters(_database.CollectionLinks
.Where(x => x.Show.Slug == showSlug)
.Select(x => (CollectionDE)x.Collection),
where,
sort,
limit);
if (!collections.Any() & await _shows.Value.Get(showSlug) == null)
throw new ItemNotFound();
return collections;
}
public async Task<ICollection<Collection>> GetFromLibrary(int id,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
ICollection<Collection> collections = await ApplyFilters(_database.LibraryLinks
.Where(x => x.LibraryID == id && x.CollectionID != null)
.Select(x => (CollectionDE)x.Collection),
where,
sort,
limit);
if (!collections.Any() && await _libraries.Value.Get(id) == null)
throw new ItemNotFound();
return collections;
}
public async Task<ICollection<Collection>> GetFromLibrary(string slug,
Expression<Func<Collection, bool>> where = null,
Sort<Collection> sort = default,
Pagination limit = default)
{
ICollection<Collection> collections = await ApplyFilters(_database.LibraryLinks
.Where(x => x.Library.Slug == slug && x.CollectionID != null)
.Select(x => (CollectionDE)x.Collection),
where,
sort,
limit);
if (!collections.Any() && await _libraries.Value.Get(slug) == null)
throw new ItemNotFound();
return collections;
}
}
}

View File

@ -15,21 +15,13 @@ namespace Kyoo.Controllers
private bool _disposed;
private readonly DatabaseContext _database;
private readonly IProviderRepository _providers;
private readonly IShowRepository _shows;
private readonly ISeasonRepository _seasons;
protected override Expression<Func<Episode, object>> DefaultSort => x => x.EpisodeNumber;
public EpisodeRepository(DatabaseContext database,
IProviderRepository providers,
IShowRepository shows,
ISeasonRepository seasons)
: base(database)
public EpisodeRepository(DatabaseContext database, IProviderRepository providers) : base(database)
{
_database = database;
_providers = providers;
_shows = shows;
_seasons = seasons;
}
@ -131,80 +123,6 @@ namespace Kyoo.Controllers
link.Provider = await _providers.CreateIfNotExists(link.Provider);
}
}
public async Task<ICollection<Episode>> GetFromShow(int showID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
ICollection<Episode> episodes = await ApplyFilters(_database.Episodes.Where(x => x.ShowID == showID),
where,
sort,
limit);
if (!episodes.Any() && await _shows.Get(showID) == null)
throw new ItemNotFound();
return episodes;
}
public async Task<ICollection<Episode>> GetFromShow(string showSlug,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
ICollection<Episode> episodes = await ApplyFilters(_database.Episodes.Where(x => x.Show.Slug == showSlug),
where,
sort,
limit);
if (!episodes.Any() && await _shows.Get(showSlug) == null)
throw new ItemNotFound();
return episodes;
}
public async Task<ICollection<Episode>> GetFromSeason(int seasonID,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
ICollection<Episode> episodes = await ApplyFilters(_database.Episodes.Where(x => x.SeasonID == seasonID),
where,
sort,
limit);
if (!episodes.Any() && await _seasons.Get(seasonID) == null)
throw new ItemNotFound();
return episodes;
}
public async Task<ICollection<Episode>> GetFromSeason(int showID,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
ICollection<Episode> episodes = await ApplyFilters(_database.Episodes.Where(x => x.ShowID == showID
&& x.SeasonNumber == seasonNumber),
where,
sort,
limit);
if (!episodes.Any() && await _seasons.Get(showID, seasonNumber) == null)
throw new ItemNotFound();
return episodes;
}
public async Task<ICollection<Episode>> GetFromSeason(string showSlug,
int seasonNumber,
Expression<Func<Episode, bool>> where = null,
Sort<Episode> sort = default,
Pagination limit = default)
{
ICollection<Episode> episodes = await ApplyFilters(_database.Episodes.Where(x => x.Show.Slug == showSlug
&& x.SeasonNumber == seasonNumber),
where,
sort,
limit);
if (!episodes.Any() && await _seasons.Get(showSlug, seasonNumber) == null)
throw new ItemNotFound();
return episodes;
}
public async Task Delete(string showSlug, int seasonNumber, int episodeNumber)
{

View File

@ -14,14 +14,12 @@ namespace Kyoo.Controllers
{
private bool _disposed;
private readonly DatabaseContext _database;
private readonly Lazy<IShowRepository> _shows;
protected override Expression<Func<GenreDE, object>> DefaultSort => x => x.Slug;
public GenreRepository(DatabaseContext database, IServiceProvider services) : base(database)
public GenreRepository(DatabaseContext database) : base(database)
{
_database = database;
_shows = new Lazy<IShowRepository>(services.GetRequiredService<IShowRepository>);
}
public override void Dispose()
@ -30,8 +28,6 @@ namespace Kyoo.Controllers
return;
_disposed = true;
_database.Dispose();
if (_shows.IsValueCreated)
_shows.Value.Dispose();
}
public override async ValueTask DisposeAsync()
@ -40,8 +36,6 @@ namespace Kyoo.Controllers
return;
_disposed = true;
await _database.DisposeAsync();
if (_shows.IsValueCreated)
await _shows.Value.DisposeAsync();
}
public override async Task<ICollection<Genre>> Search(string query)
@ -71,36 +65,5 @@ namespace Kyoo.Controllers
_database.Entry(link).State = EntityState.Deleted;
await _database.SaveChangesAsync();
}
public async Task<ICollection<Genre>> GetFromShow(int showID,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default)
{
ICollection<Genre> genres = await ApplyFilters(_database.GenreLinks.Where(x => x.ShowID == showID)
.Select(x => (GenreDE)x.Genre),
where,
sort,
limit);
if (!genres.Any() && await _shows.Value.Get(showID) == null)
throw new ItemNotFound();
return genres;
}
public async Task<ICollection<Genre>> GetFromShow(string showSlug,
Expression<Func<Genre, bool>> where = null,
Sort<Genre> sort = default,
Pagination limit = default)
{
ICollection<Genre> genres = await ApplyFilters(_database.GenreLinks
.Where(x => x.Show.Slug == showSlug)
.Select(x => (GenreDE)x.Genre),
where,
sort,
limit);
if (!genres.Any() && await _shows.Value.Get(showSlug) == null)
throw new ItemNotFound();
return genres;
}
}
}

View File

@ -15,16 +15,14 @@ namespace Kyoo.Controllers
private bool _disposed;
private readonly DatabaseContext _database;
private readonly IProviderRepository _providers;
private readonly Lazy<IShowRepository> _shows;
protected override Expression<Func<LibraryDE, object>> DefaultSort => x => x.ID;
public LibraryRepository(DatabaseContext database, IProviderRepository providers, IServiceProvider services)
public LibraryRepository(DatabaseContext database, IProviderRepository providers)
: base(database)
{
_database = database;
_providers = providers;
_shows = new Lazy<IShowRepository>(services.GetRequiredService<IShowRepository>);
}
public override void Dispose()
@ -34,8 +32,6 @@ namespace Kyoo.Controllers
_disposed = true;
_database.Dispose();
_providers.Dispose();
if (_shows.IsValueCreated)
_shows.Value.Dispose();
}
public override async ValueTask DisposeAsync()
@ -45,8 +41,6 @@ namespace Kyoo.Controllers
_disposed = true;
await _database.DisposeAsync();
await _providers.DisposeAsync();
if (_shows.IsValueCreated)
await _shows.Value.DisposeAsync();
}
public override async Task<ICollection<Library>> Search(string query)
@ -99,69 +93,5 @@ namespace Kyoo.Controllers
_database.Entry(entry).State = EntityState.Deleted;
await _database.SaveChangesAsync();
}
public async Task<ICollection<Library>> GetFromShow(int showID,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
ICollection<Library> libraries = await ApplyFilters(_database.LibraryLinks
.Where(x => x.ShowID == showID)
.Select(x => (LibraryDE)x.Library),
where,
sort,
limit);
if (!libraries.Any() && await _shows.Value.Get(showID) == null)
throw new ItemNotFound();
return libraries;
}
public async Task<ICollection<Library>> GetFromShow(string showSlug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
ICollection<Library> libraries = await ApplyFilters(_database.LibraryLinks
.Where(x => x.Show.Slug == showSlug)
.Select(x => (LibraryDE)x.Library),
where,
sort,
limit);
if (!libraries.Any() && await _shows.Value.Get(showSlug) == null)
throw new ItemNotFound();
return libraries;
}
public async Task<ICollection<Library>> GetFromCollection(int id,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
ICollection<Library> libraries = await ApplyFilters(_database.LibraryLinks
.Where(x => x.CollectionID == id)
.Select(x => (LibraryDE)x.Library),
where,
sort,
limit);
if (!libraries.Any() && await _shows.Value.Get(id) == null)
throw new ItemNotFound();
return libraries;
}
public async Task<ICollection<Library>> GetFromCollection(string slug,
Expression<Func<Library, bool>> where = null,
Sort<Library> sort = default,
Pagination limit = default)
{
ICollection<Library> libraries = await ApplyFilters(_database.LibraryLinks
.Where(x => x.Collection.Slug == slug)
.Select(x => (LibraryDE)x.Library),
where,
sort,
limit);
if (!libraries.Any() && await _shows.Value.Get(slug) == null)
throw new ItemNotFound();
return libraries;
}
}
}

View File

@ -98,16 +98,6 @@ namespace Kyoo.Controllers
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
if (sort.Key?.Body is MemberExpression member)
{
sort.Key = member.Member.Name switch
{
"Name" => x => x.People.Name,
"Slug" => x => x.People.Slug,
_ => sort.Key
};
}
ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles.Where(x => x.ShowID == showID),
id => _database.PeopleRoles.FirstOrDefaultAsync(x => x.ID == id),
x => x.People.Name,
@ -124,16 +114,6 @@ namespace Kyoo.Controllers
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
if (sort.Key?.Body is MemberExpression member)
{
sort.Key = member.Member.Name switch
{
"Name" => x => x.People.Name,
"Slug" => x => x.People.Slug,
_ => sort.Key
};
}
ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles.Where(x => x.Show.Slug == showSlug),
id => _database.PeopleRoles.FirstOrDefaultAsync(x => x.ID == id),
x => x.People.Name,

View File

@ -17,20 +17,17 @@ namespace Kyoo.Controllers
private readonly DatabaseContext _database;
private readonly IProviderRepository _providers;
private readonly Lazy<IEpisodeRepository> _episodes;
private readonly IShowRepository _shows;
protected override Expression<Func<Season, object>> DefaultSort => x => x.SeasonNumber;
public SeasonRepository(DatabaseContext database,
IProviderRepository providers,
IShowRepository shows,
IServiceProvider services)
: base(database)
{
_database = database;
_providers = providers;
_episodes = new Lazy<IEpisodeRepository>(services.GetRequiredService<IEpisodeRepository>);
_shows = shows;
}
@ -111,34 +108,6 @@ namespace Kyoo.Controllers
}
}
public async Task<ICollection<Season>> GetFromShow(int showID,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default)
{
ICollection<Season> seasons = await ApplyFilters(_database.Seasons.Where(x => x.ShowID == showID),
where,
sort,
limit);
if (!seasons.Any() && await _shows.Get(showID) == null)
throw new ItemNotFound();
return seasons;
}
public async Task<ICollection<Season>> GetFromShow(string showSlug,
Expression<Func<Season, bool>> where = null,
Sort<Season> sort = default,
Pagination limit = default)
{
ICollection<Season> seasons = await ApplyFilters(_database.Seasons.Where(x => x.Show.Slug == showSlug),
where,
sort,
limit);
if (!seasons.Any() && await _shows.Get(showSlug) == null)
throw new ItemNotFound();
return seasons;
}
public async Task Delete(string showSlug, int seasonNumber)
{
Season obj = await Get(showSlug, seasonNumber);
@ -161,10 +130,5 @@ namespace Kyoo.Controllers
if (obj.Episodes != null)
await _episodes.Value.DeleteRange(obj.Episodes);
}
public Task<Season> GetFromEpisode(int episodeID)
{
return _database.Seasons.FirstOrDefaultAsync(x => x.Episodes.Any(y => y.ID == episodeID));
}
}
}

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@ -20,8 +19,6 @@ namespace Kyoo.Controllers
private readonly IProviderRepository _providers;
private readonly Lazy<ISeasonRepository> _seasons;
private readonly Lazy<IEpisodeRepository> _episodes;
private readonly Lazy<ILibraryRepository> _libraries;
private readonly Lazy<ICollectionRepository> _collections;
protected override Expression<Func<ShowDE, object>> DefaultSort => x => x.Title;
public ShowRepository(DatabaseContext database,
@ -39,8 +36,6 @@ namespace Kyoo.Controllers
_providers = providers;
_seasons = new Lazy<ISeasonRepository>(services.GetRequiredService<ISeasonRepository>);
_episodes = new Lazy<IEpisodeRepository>(services.GetRequiredService<IEpisodeRepository>);
_libraries = new Lazy<ILibraryRepository>(services.GetRequiredService<ILibraryRepository>);
_collections = new Lazy<ICollectionRepository>(services.GetRequiredService<ICollectionRepository>);
}
public override void Dispose()
@ -57,10 +52,6 @@ namespace Kyoo.Controllers
_seasons.Value.Dispose();
if (_episodes.IsValueCreated)
_episodes.Value.Dispose();
if (_libraries.IsValueCreated)
_libraries.Value.Dispose();
if (_collections.IsValueCreated)
_collections.Value.Dispose();
}
public override async ValueTask DisposeAsync()
@ -77,10 +68,6 @@ namespace Kyoo.Controllers
await _seasons.Value.DisposeAsync();
if (_episodes.IsValueCreated)
await _episodes.Value.DisposeAsync();
if (_libraries.IsValueCreated)
await _libraries.Value.DisposeAsync();
if (_collections.IsValueCreated)
await _collections.Value.DisposeAsync();
}
public override async Task<ICollection<Show>> Search(string query)
@ -186,83 +173,5 @@ namespace Kyoo.Controllers
if (obj.Episodes != null)
await _episodes.Value.DeleteRange(obj.Episodes);
}
public async Task<ICollection<Show>> GetFromLibrary(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
ICollection<Show> shows = await ApplyFilters(_database.LibraryLinks
.Where(x => x.LibraryID == id && x.ShowID != null)
.Select(x => (ShowDE)x.Show),
where,
sort,
limit);
if (!shows.Any() && await _libraries.Value.Get(id) == null)
throw new ItemNotFound();
return shows;
}
public async Task<ICollection<Show>> GetFromLibrary(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
ICollection<Show> shows = await ApplyFilters(_database.LibraryLinks
.Where(x => x.Library.Slug == slug && x.ShowID != null)
.Select(x => (ShowDE)x.Show),
where,
sort,
limit);
if (!shows.Any() && await _libraries.Value.Get(slug) == null)
throw new ItemNotFound();
return shows;
}
public async Task<ICollection<Show>> GetFromCollection(int id,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
ICollection<Show> shows = await ApplyFilters(_database.CollectionLinks
.Where(x => x.CollectionID== id)
.Select(x => (ShowDE)x.Show),
where,
sort,
limit);
if (!shows.Any() && await _libraries.Value.Get(id) == null)
throw new ItemNotFound();
return shows;
}
public async Task<ICollection<Show>> GetFromCollection(string slug,
Expression<Func<Show, bool>> where = null,
Sort<Show> sort = default,
Pagination limit = default)
{
ICollection<Show> shows = await ApplyFilters(_database.CollectionLinks
.Where(x => x.Collection.Slug == slug)
.Select(x => (ShowDE)x.Show),
where,
sort,
limit);
if (!shows.Any() && await _libraries.Value.Get(slug) == null)
throw new ItemNotFound();
return shows;
}
public Task<Show> GetFromSeason(int seasonID)
{
return _database.Shows
.FirstOrDefaultAsync(x => x.Seasons.Any(y => y.ID == seasonID))
.Cast<Show>();
}
public Task<Show> GetFromEpisode(int episodeID)
{
return _database.Shows
.FirstOrDefaultAsync(x => x.Episodes.Any(y => y.ID == episodeID))
.Cast<Show>();
}
}
}

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
namespace Kyoo.Controllers
@ -48,27 +47,5 @@ namespace Kyoo.Controllers
show.StudioID = null;
await _database.SaveChangesAsync();
}
public async Task<Studio> GetFromShow(int showID)
{
Studio studio = await _database.Shows
.Where(x => x.ID == showID)
.Select(x => x.Studio)
.FirstOrDefaultAsync();
if (studio == null && !_database.Shows.Any(x => x.ID == showID))
throw new ItemNotFound();
return studio;
}
public async Task<Studio> GetFromShow(string showSlug)
{
Studio studio = await _database.Shows
.Where(x => x.Slug == showSlug)
.Select(x => x.Studio)
.FirstOrDefaultAsync();
if (studio == null && !_database.Shows.Any(x => x.Slug == showSlug))
throw new ItemNotFound();
return studio;
}
}
}

View File

@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@ -15,14 +12,12 @@ namespace Kyoo.Controllers
{
private bool _disposed;
private readonly DatabaseContext _database;
private readonly Lazy<IEpisodeRepository> _episodes;
protected override Expression<Func<Track, object>> DefaultSort => x => x.ID;
public TrackRepository(DatabaseContext database, IServiceProvider services) : base(database)
public TrackRepository(DatabaseContext database) : base(database)
{
_database = database;
_episodes = new Lazy<IEpisodeRepository>(services.GetRequiredService<IEpisodeRepository>);
}
public override void Dispose()
@ -31,8 +26,6 @@ namespace Kyoo.Controllers
return;
_disposed = true;
_database.Dispose();
if (_episodes.IsValueCreated)
_episodes.Value.Dispose();
}
public override async ValueTask DisposeAsync()
@ -41,8 +34,6 @@ namespace Kyoo.Controllers
return;
_disposed = true;
await _database.DisposeAsync();
if (_episodes.IsValueCreated)
await _episodes.Value.DisposeAsync();
}
public override Task<Track> Get(string slug)
@ -97,55 +88,5 @@ namespace Kyoo.Controllers
_database.Entry(obj).State = EntityState.Deleted;
await _database.SaveChangesAsync();
}
public async Task<ICollection<Track>> GetFromEpisode(int episodeID,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default)
{
ICollection<Track> tracks = await ApplyFilters(_database.Tracks.Where(x => x.EpisodeID == episodeID),
where,
sort,
limit);
if (!tracks.Any() && await _episodes.Value.Get(episodeID) == null)
throw new ItemNotFound();
return tracks;
}
public async Task<ICollection<Track>> GetFromEpisode(int showID,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default)
{
ICollection<Track> tracks = await ApplyFilters(_database.Tracks.Where(x => x.Episode.ShowID == showID
&& x.Episode.SeasonNumber == seasonNumber
&& x.Episode.EpisodeNumber == episodeNumber),
where,
sort,
limit);
if (!tracks.Any() && await _episodes.Value.Get(showID, seasonNumber, episodeNumber) == null)
throw new ItemNotFound();
return tracks;
}
public async Task<ICollection<Track>> GetFromEpisode(string showSlug,
int seasonNumber,
int episodeNumber,
Expression<Func<Track, bool>> where = null,
Sort<Track> sort = default,
Pagination limit = default)
{
ICollection<Track> tracks = await ApplyFilters(_database.Tracks.Where(x => x.Episode.Show.Slug == showSlug
&& x.Episode.SeasonNumber == seasonNumber
&& x.Episode.EpisodeNumber == episodeNumber),
where,
sort,
limit);
if (!tracks.Any() && await _episodes.Value.Get(showSlug, seasonNumber, episodeNumber) == null)
throw new ItemNotFound();
return tracks;
}
}
}

View File

@ -8,6 +8,7 @@ namespace Kyoo.Models
public class CollectionDE : Collection
{
[JsonIgnore] [NotMergable] public virtual IEnumerable<CollectionLink> Links { get; set; }
[ExpressionRewrite(nameof(Links), nameof(CollectionLink.Show))]
public override IEnumerable<Show> Shows
{
get => Links?.Select(x => x.Show);
@ -15,7 +16,9 @@ namespace Kyoo.Models
}
[JsonIgnore] [NotMergable] public virtual IEnumerable<LibraryLink> LibraryLinks { get; set; }
/*[ExpressionRewrite(x => x.LibraryLinks, y => y.Genre)]*/ public override IEnumerable<Library> Libraries
[ExpressionRewrite(nameof(LibraryLinks), nameof(GenreLink.Genre))]
public override IEnumerable<Library> Libraries
{
get => LibraryLinks?.Select(x => x.Library);
set => LibraryLinks = value?.Select(x => new LibraryLink(x, this));

View File

@ -9,6 +9,7 @@ namespace Kyoo.Models
{
[JsonIgnore] [NotMergable] public virtual IEnumerable<GenreLink> Links { get; set; }
[ExpressionRewrite(nameof(Links), nameof(GenreLink.Genre))]
[JsonIgnore] [NotMergable] public override IEnumerable<Show> Shows
{
get => Links?.Select(x => x.Show);

View File

@ -8,6 +8,7 @@ namespace Kyoo.Models
public class LibraryDE : Library
{
[JsonIgnore] [NotMergable] public virtual IEnumerable<ProviderLink> ProviderLinks { get; set; }
[ExpressionRewrite(nameof(ProviderLinks), nameof(ProviderLink.Provider))]
public override IEnumerable<ProviderID> Providers
{
get => ProviderLinks?.Select(x => x.Provider);
@ -15,6 +16,7 @@ namespace Kyoo.Models
}
[JsonIgnore] [NotMergable] public virtual IEnumerable<LibraryLink> Links { get; set; }
[ExpressionRewrite(nameof(Links), nameof(LibraryLink.Show))]
public override IEnumerable<Show> Shows
{
get => Links?.Where(x => x.Show != null).Select(x => x.Show);
@ -22,6 +24,7 @@ namespace Kyoo.Models
value?.Select(x => new LibraryLink(this, x)),
Links?.Where(x => x.Show == null));
}
[ExpressionRewrite(nameof(Links), nameof(LibraryLink.Collection))]
public override IEnumerable<Collection> Collections
{
get => Links?.Where(x => x.Collection != null).Select(x => x.Collection);

View File

@ -11,6 +11,7 @@ namespace Kyoo.Models
public class ShowDE : Show
{
[JsonIgnore] [NotMergable] public virtual IEnumerable<GenreLink> GenreLinks { get; set; }
[ExpressionRewrite(nameof(GenreLinks), nameof(GenreLink.Genre))]
public override IEnumerable<Genre> Genres
{
get => GenreLinks?.Select(x => x.Genre);
@ -18,6 +19,7 @@ namespace Kyoo.Models
}
[JsonIgnore] [NotMergable] public virtual IEnumerable<LibraryLink> LibraryLinks { get; set; }
[ExpressionRewrite(nameof(LibraryLinks), nameof(LibraryLink.Library))]
public override IEnumerable<Library> Libraries
{
get => LibraryLinks?.Select(x => x.Library);
@ -25,7 +27,7 @@ namespace Kyoo.Models
}
[JsonIgnore] [NotMergable] public virtual IEnumerable<CollectionLink> CollectionLinks { get; set; }
[ExpressionRewrite(nameof(CollectionLinks), nameof(CollectionLink.Collection))]
public override IEnumerable<Collection> Collections
{
get => CollectionLinks?.Select(x => x.Collection);

View File

@ -63,7 +63,7 @@ namespace Kyoo.Controllers
if (!Directory.Exists(show.Path))
await libraryManager.DeleteShow(show);
ICollection<Episode> episodes = await libraryManager.GetEpisodesFromShow();
ICollection<Episode> episodes = await libraryManager.GetEpisodes();
ICollection<Library> libraries = argument == null
? await libraryManager.GetLibraries()
: new [] { await libraryManager.GetLibrary(argument)};

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Kyoo.Controllers;
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
@ -39,8 +40,8 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShowsFromCollection(id,
ApiHelper.ParseWhere<Show>(where),
ICollection<Show> ressources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Collections.Any(y => y.ID == id)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
@ -71,8 +72,8 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShowsFromCollection(slug,
ApiHelper.ParseWhere<Show>(where),
ICollection<Show> ressources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Collections.Any(y => y.Slug == slug)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
@ -103,8 +104,8 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibrariesFromCollection(id,
ApiHelper.ParseWhere<Library>(where),
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Collections.Any(y => y.ID == id)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
@ -135,8 +136,8 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibrariesFromCollection(slug,
ApiHelper.ParseWhere<Library>(where),
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Collections.Any(y => y.Slug == slug)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));

View File

@ -2,6 +2,7 @@
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kyoo.CommonApi;
using Kyoo.Controllers;
@ -28,7 +29,7 @@ namespace Kyoo.Api
[Authorize(Policy = "Read")]
public async Task<ActionResult<Show>> GetShow(int episodeID)
{
return await _libraryManager.GetShowFromEpisode(episodeID);
return await _libraryManager.GetShow(x => x.Episodes.Any(y => y.ID == episodeID));
}
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}/show")]
@ -49,7 +50,7 @@ namespace Kyoo.Api
[Authorize(Policy = "Read")]
public async Task<ActionResult<Season>> GetSeason(int episodeID)
{
return await _libraryManager.GetSeasonFromEpisode(episodeID);
return await _libraryManager.GetSeason(x => x.Episodes.Any(y => y.ID == episodeID));
}
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}/season")]
@ -81,8 +82,8 @@ namespace Kyoo.Api
try
{
ICollection<Track> ressources = await _libraryManager.GetTracksFromEpisode(episodeID,
ApiHelper.ParseWhere<Track>(where),
ICollection<Track> ressources = await _libraryManager.GetTracks(
ApiHelper.ParseWhere<Track>(where, x => x.Episode.ID == episodeID),
new Sort<Track>(sortBy),
new Pagination(limit, afterID));
@ -115,10 +116,10 @@ namespace Kyoo.Api
try
{
ICollection<Track> ressources = await _libraryManager.GetTracksFromEpisode(showID,
seasonNumber,
episodeNumber,
ApiHelper.ParseWhere<Track>(where),
ICollection<Track> ressources = await _libraryManager.GetTracks(
ApiHelper.ParseWhere<Track>(where, x => x.Episode.ShowID == showID
&& x.Episode.SeasonNumber == seasonNumber
&& x.Episode.EpisodeNumber == episodeNumber),
new Sort<Track>(sortBy),
new Pagination(limit, afterID));
@ -151,10 +152,9 @@ namespace Kyoo.Api
try
{
ICollection<Track> ressources = await _libraryManager.GetTracksFromEpisode(showSlug,
seasonNumber,
episodeNumber,
ApiHelper.ParseWhere<Track>(where),
ICollection<Track> ressources = await _libraryManager.GetTracks(ApiHelper.ParseWhere<Track>(where, x => x.Episode.Show.Slug == showSlug
&& x.Episode.SeasonNumber == seasonNumber
&& x.Episode.EpisodeNumber == episodeNumber),
new Sort<Track>(sortBy),
new Pagination(limit, afterID));

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Kyoo.Controllers;
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
@ -50,8 +51,8 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShowsFromLibrary(id,
ApiHelper.ParseWhere<Show>(where),
ICollection<Show> ressources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Libraries.Any(y => y.ID == id)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
@ -82,8 +83,8 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShowsFromLibrary(slug,
ApiHelper.ParseWhere<Show>(where),
ICollection<Show> ressources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Libraries.Any(y => y.Slug == slug)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
@ -114,8 +115,8 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollectionsFromLibrary(id,
ApiHelper.ParseWhere<Collection>(where),
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Libraries.Any(y => y.ID == id)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));
@ -146,8 +147,8 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollectionsFromLibrary(slug,
ApiHelper.ParseWhere<Collection>(where),
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Libraries.Any(y => y.Slug == slug)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));

View File

@ -7,6 +7,7 @@ using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Microsoft.Extensions.Configuration;
namespace Kyoo.Api
@ -39,8 +40,8 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodesFromSeason(seasonID,
ApiHelper.ParseWhere<Episode>(where),
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.SeasonID == seasonID),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
@ -72,9 +73,9 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodesFromSeason(showSlug,
seasonNumber,
ApiHelper.ParseWhere<Episode>(where),
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.Show.Slug == showSlug
&& x.SeasonNumber == seasonNumber),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
@ -106,9 +107,8 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodesFromSeason(showID,
seasonNumber,
ApiHelper.ParseWhere<Episode>(where),
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.ShowID == showID && x.SeasonNumber == seasonNumber),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
@ -128,7 +128,7 @@ namespace Kyoo.Api
[Authorize(Policy = "Read")]
public async Task<ActionResult<Show>> GetShow(int seasonID)
{
return await _libraryManager.GetShowFromSeason(seasonID);
return await _libraryManager.GetShow(x => x.Seasons.Any(y => y.ID == seasonID));
}
[HttpGet("{showSlug}-s{seasonNumber:int}/show")]

View File

@ -2,6 +2,7 @@
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kyoo.CommonApi;
using Kyoo.Controllers;
@ -39,8 +40,8 @@ namespace Kyoo.Api
try
{
ICollection<Season> ressources = await _libraryManager.GetSeasonsFromShow(showID,
ApiHelper.ParseWhere<Season>(where),
ICollection<Season> ressources = await _libraryManager.GetSeasons(
ApiHelper.ParseWhere<Season>(where, x => x.ShowID == showID),
new Sort<Season>(sortBy),
new Pagination(limit, afterID));
@ -71,8 +72,8 @@ namespace Kyoo.Api
try
{
ICollection<Season> ressources = await _libraryManager.GetSeasonsFromShow(slug,
ApiHelper.ParseWhere<Season>(where),
ICollection<Season> ressources = await _libraryManager.GetSeasons(
ApiHelper.ParseWhere<Season>(where, x => x.Show.Slug == slug),
new Sort<Season>(sortBy),
new Pagination(limit, afterID));
@ -103,8 +104,8 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodesFromShow(showID,
ApiHelper.ParseWhere<Episode>(where),
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.ShowID == showID),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
@ -135,8 +136,8 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodesFromShow(slug,
ApiHelper.ParseWhere<Episode>(where),
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.Show.Slug == slug),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
@ -229,8 +230,8 @@ namespace Kyoo.Api
try
{
ICollection<Genre> ressources = await _libraryManager.GetGenresFromShow(showID,
ApiHelper.ParseWhere<Genre>(where),
ICollection<Genre> ressources = await _libraryManager.GetGenres(
ApiHelper.ParseWhere<Genre>(where, x => x.Shows.Any(y => y.ID == showID)),
new Sort<Genre>(sortBy),
new Pagination(limit, afterID));
@ -261,8 +262,8 @@ namespace Kyoo.Api
try
{
ICollection<Genre> ressources = await _libraryManager.GetGenresFromShow(slug,
ApiHelper.ParseWhere<Genre>(where),
ICollection<Genre> ressources = await _libraryManager.GetGenres(
ApiHelper.ParseWhere<Genre>(where, x => x.Shows.Any(y => y.Slug == slug)),
new Sort<Genre>(sortBy),
new Pagination(limit, afterID));
@ -284,7 +285,7 @@ namespace Kyoo.Api
{
try
{
return await _libraryManager.GetStudioFromShow(showID);
return await _libraryManager.GetStudio(x => x.Shows.Any(y => y.ID == showID));
}
catch (ItemNotFound)
{
@ -298,7 +299,7 @@ namespace Kyoo.Api
{
try
{
return await _libraryManager.GetStudioFromShow(slug);
return await _libraryManager.GetStudio(x => x.Shows.Any(y => y.Slug == slug));
}
catch (ItemNotFound)
{
@ -321,8 +322,8 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibrariesFromShow(showID,
ApiHelper.ParseWhere<Library>(where),
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Shows.Any(y => y.ID == showID)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
@ -353,8 +354,8 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibrariesFromShow(slug,
ApiHelper.ParseWhere<Library>(where),
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Shows.Any(y => y.Slug == slug)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
@ -385,8 +386,8 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollectionsFromShow(showID,
ApiHelper.ParseWhere<Collection>(where),
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Shows.Any(y => y.ID == showID)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));
@ -417,8 +418,8 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollectionsFromShow(slug,
ApiHelper.ParseWhere<Collection>(where),
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Shows.Any(y => y.Slug == slug)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));