diff --git a/Kyoo.Common/Controllers/IRepository.cs b/Kyoo.Common/Controllers/IRepository.cs index 41729858..21f3318a 100644 --- a/Kyoo.Common/Controllers/IRepository.cs +++ b/Kyoo.Common/Controllers/IRepository.cs @@ -209,24 +209,13 @@ namespace Kyoo.Controllers public interface IProviderRepository : IRepository { - Task> GetFromShow(int showID, - Expression> where = null, + Task> GetMetadataID(Expression> where = null, Sort sort = default, Pagination limit = default); - Task> GetFromShow(int showID, - [Optional] Expression> where, - Expression> sort = default, + + Task> GetMetadataID([Optional] Expression> where, + Expression> sort, Pagination limit = default - ) => GetFromShow(showID, where, new Sort(sort), limit); - - Task> GetFromShow(string showSlug, - Expression> where = null, - Sort sort = default, - Pagination limit = default); - Task> GetFromShow(string showSlug, - [Optional] Expression> where, - Expression> sort = default, - Pagination limit = default - ) => GetFromShow(showSlug, where, new Sort(sort), limit); + ) => GetMetadataID(where, new Sort(sort), limit); } } diff --git a/Kyoo.Common/Controllers/Implementations/LibraryManager.cs b/Kyoo.Common/Controllers/Implementations/LibraryManager.cs index be012f1b..1c3b7543 100644 --- a/Kyoo.Common/Controllers/Implementations/LibraryManager.cs +++ b/Kyoo.Common/Controllers/Implementations/LibraryManager.cs @@ -276,12 +276,12 @@ namespace Kyoo.Controllers (Collection c, Library) => LibraryRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => c.Libraries = x), - (Show s, MetadataID) => ProviderRepository.Get(Utility.ResourceEquals(obj)) + (Show s, MetadataID) => ProviderRepository.GetMetadataID(x => x.ShowID == obj.ID) .Then(x => s.ExternalIDs = x), (Show s, Genre) => GenreRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => s.Genres = x), - (Show s, PeopleRole) => PeopleRepository.GetFromShow(Utility.ResourceEquals(obj)) - .Then(x => s.People = x), + (Show s, PeopleRole) => (PeopleRepository.GetFromShow((dynamic)(obj.ID > 0 ? obj.ID : obj.Slug)) + as Task>).Then(x => s.People = x), (Show s, Season) => SeasonRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => s.Seasons = x), (Show s, Episode) => EpisodeRepository.GetAll(Utility.ResourceEquals(obj)) @@ -291,12 +291,12 @@ namespace Kyoo.Controllers (Show s, Collection) => CollectionRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => s.Collections = x), - (Season s, MetadataID) => ProviderRepository.GetAll(Utility.ResourceEquals(obj)) + (Season s, MetadataID) => ProviderRepository.GetMetadataID(x => x.SeasonID == obj.ID) .Then(x => s.ExternalIDs = x), (Season s, Episode) => EpisodeRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => s.Episodes = x), - (Episode e, MetadataID) => ProviderRepository.GetAll(Utility.ResourceEquals(obj)) + (Episode e, MetadataID) => ProviderRepository.GetMetadataID(x => x.EpisodeID == obj.ID) .Then(x => e.ExternalIDs = x), (Episode e, Track) => TrackRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => e.Tracks = x), @@ -307,10 +307,10 @@ namespace Kyoo.Controllers (Studio s, Show) => ShowRepository.GetAll(Utility.ResourceEquals(obj)) .Then(x => s.Shows = x), - (People p, MetadataID) => ProviderRepository.GetAll(Utility.ResourceEquals(obj)) + (People p, MetadataID) => ProviderRepository.GetMetadataID(x => x.PeopleID == obj.ID) .Then(x => p.ExternalIDs = x), - (People p, PeopleRole) => PeopleRepository.GetFromPeople(Utility.ResourceEquals(obj)) - .Then(x => p.Roles = x), + (People p, PeopleRole) => (PeopleRepository.GetFromPeople((dynamic)(obj.ID > 0 ? obj.ID : obj.Slug)) + as Task>).Then(x => p.Roles = x), _ => throw new ArgumentException($"Couldn't find a way to load {member} of {typeof(T).Name}.") }; diff --git a/Kyoo/Controllers/Repositories/ProviderRepository.cs b/Kyoo/Controllers/Repositories/ProviderRepository.cs index 6219a919..9dd112c0 100644 --- a/Kyoo/Controllers/Repositories/ProviderRepository.cs +++ b/Kyoo/Controllers/Repositories/ProviderRepository.cs @@ -45,5 +45,17 @@ namespace Kyoo.Controllers // TODO handle ExternalID deletion when they refer to this providerID. await _database.SaveChangesAsync(); } + + public Task> GetMetadataID(Expression> where = null, + Sort sort = default, + Pagination limit = default) + { + return ApplyFilters(_database.MetadataIds, + x => _database.MetadataIds.FirstOrDefaultAsync(y => y.ID == x), + x => x.ID, + where, + sort, + limit); + } } } \ No newline at end of file