// Kyoo - A portable and vast media library solution. // Copyright (c) Kyoo. // // See AUTHORS.md and LICENSE file in the project root for full license information. // // Kyoo is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // Kyoo is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Runtime.InteropServices; using System.Threading.Tasks; using JetBrains.Annotations; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; namespace Kyoo.Abstractions.Controllers { /// /// An interface to interact with the database. Every repository is mapped through here. /// public interface ILibraryManager { /// /// Get the repository corresponding to the T item. /// /// The type you want /// If the item is not found /// The repository corresponding IRepository GetRepository() where T : class, IResource; /// /// The repository that handle libraries. /// ILibraryRepository LibraryRepository { get; } /// /// The repository that handle libraries items (a wrapper around shows and collections). /// ILibraryItemRepository LibraryItemRepository { get; } /// /// The repository that handle collections. /// ICollectionRepository CollectionRepository { get; } /// /// The repository that handle shows. /// IShowRepository ShowRepository { get; } /// /// The repository that handle seasons. /// ISeasonRepository SeasonRepository { get; } /// /// The repository that handle episodes. /// IEpisodeRepository EpisodeRepository { get; } /// /// The repository that handle tracks. /// ITrackRepository TrackRepository { get; } /// /// The repository that handle people. /// IPeopleRepository PeopleRepository { get; } /// /// The repository that handle studios. /// IStudioRepository StudioRepository { get; } /// /// The repository that handle genres. /// IGenreRepository GenreRepository { get; } /// /// The repository that handle providers. /// IProviderRepository ProviderRepository { get; } /// /// The repository that handle users. /// IUserRepository UserRepository { get; } /// /// Get the resource by it's ID /// /// The id of the resource /// The type of the resource /// If the item is not found /// The resource found [ItemNotNull] Task Get(int id) where T : class, IResource; /// /// Get the resource by it's slug /// /// The slug of the resource /// The type of the resource /// If the item is not found /// The resource found [ItemNotNull] Task Get(string slug) where T : class, IResource; /// /// Get the resource by a filter function. /// /// The filter function. /// The type of the resource /// If the item is not found /// The first resource found that match the where function [ItemNotNull] Task Get(Expression> where) where T : class, IResource; /// /// Get a season from it's showID and it's seasonNumber /// /// The id of the show /// The season's number /// If the item is not found /// The season found [ItemNotNull] Task Get(int showID, int seasonNumber); /// /// Get a season from it's show slug and it's seasonNumber /// /// The slug of the show /// The season's number /// If the item is not found /// The season found [ItemNotNull] Task Get(string showSlug, int seasonNumber); /// /// Get a episode from it's showID, it's seasonNumber and it's episode number. /// /// The id of the show /// The season's number /// The episode's number /// If the item is not found /// The episode found [ItemNotNull] Task Get(int showID, int seasonNumber, int episodeNumber); /// /// Get a episode from it's show slug, it's seasonNumber and it's episode number. /// /// The slug of the show /// The season's number /// The episode's number /// If the item is not found /// The episode found [ItemNotNull] Task Get(string showSlug, int seasonNumber, int episodeNumber); /// /// Get the resource by it's ID or null if it is not found. /// /// The id of the resource /// The type of the resource /// The resource found [ItemCanBeNull] Task GetOrDefault(int id) where T : class, IResource; /// /// Get the resource by it's slug or null if it is not found. /// /// The slug of the resource /// The type of the resource /// The resource found [ItemCanBeNull] Task GetOrDefault(string slug) where T : class, IResource; /// /// Get the resource by a filter function or null if it is not found. /// /// The filter function. /// The type of the resource /// The first resource found that match the where function [ItemCanBeNull] Task GetOrDefault(Expression> where) where T : class, IResource; /// /// Get a season from it's showID and it's seasonNumber or null if it is not found. /// /// The id of the show /// The season's number /// The season found [ItemCanBeNull] Task GetOrDefault(int showID, int seasonNumber); /// /// Get a season from it's show slug and it's seasonNumber or null if it is not found. /// /// The slug of the show /// The season's number /// The season found [ItemCanBeNull] Task GetOrDefault(string showSlug, int seasonNumber); /// /// Get a episode from it's showID, it's seasonNumber and it's episode number or null if it is not found. /// /// The id of the show /// The season's number /// The episode's number /// The episode found [ItemCanBeNull] Task GetOrDefault(int showID, int seasonNumber, int episodeNumber); /// /// Get a episode from it's show slug, it's seasonNumber and it's episode number or null if it is not found. /// /// The slug of the show /// The season's number /// The episode's number /// The episode found [ItemCanBeNull] Task GetOrDefault(string showSlug, int seasonNumber, int episodeNumber); /// /// Load a related resource /// /// The source object. /// A getter function for the member to load /// /// true if you want to load the relation even if it is not null, false otherwise. /// /// The type of the source object /// The related resource's type /// The param /// /// /// Task Load([NotNull] T obj, Expression> member, bool force = false) where T : class, IResource where T2 : class, IResource; /// /// Load a collection of related resource /// /// The source object. /// A getter function for the member to load /// /// true if you want to load the relation even if it is not null, false otherwise. /// /// The type of the source object /// The related resource's type /// The param /// /// /// Task Load([NotNull] T obj, Expression>> member, bool force = false) where T : class, IResource where T2 : class; /// /// Load a related resource by it's name /// /// The source object. /// The name of the resource to load (case sensitive) /// /// true if you want to load the relation even if it is not null, false otherwise. /// /// The type of the source object /// The param /// /// /// Task Load([NotNull] T obj, string memberName, bool force = false) where T : class, IResource; /// /// Load a related resource without specifying it's type. /// /// The source object. /// The name of the resource to load (case sensitive) /// /// true if you want to load the relation even if it is not null, false otherwise. /// /// /// /// /// A representing the asynchronous operation. Task Load([NotNull] IResource obj, string memberName, bool force = false); /// /// Get items (A wrapper around shows or collections) from a library. /// /// The ID of the library /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// A list of items that match every filters Task> GetItemsFromLibrary(int id, Expression> where = null, Sort sort = default, Pagination limit = default); /// /// Get items (A wrapper around shows or collections) from a library. /// /// The ID of the library /// A filter function /// A sort by method /// How many items to return and where to start /// A list of items that match every filters Task> GetItemsFromLibrary(int id, [Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetItemsFromLibrary(id, where, new Sort(sort), limit); /// /// Get items (A wrapper around shows or collections) from a library. /// /// The slug of the library /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// A list of items that match every filters Task> GetItemsFromLibrary(string slug, Expression> where = null, Sort sort = default, Pagination limit = default); /// /// Get items (A wrapper around shows or collections) from a library. /// /// The slug of the library /// A filter function /// A sort by method /// How many items to return and where to start /// A list of items that match every filters Task> GetItemsFromLibrary(string slug, [Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetItemsFromLibrary(slug, where, new Sort(sort), limit); /// /// Get people's roles from a show. /// /// The ID of the show /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// A list of items that match every filters Task> GetPeopleFromShow(int showID, Expression> where = null, Sort sort = default, Pagination limit = default); /// /// Get people's roles from a show. /// /// The ID of the show /// A filter function /// A sort by method /// How many items to return and where to start /// A list of items that match every filters Task> GetPeopleFromShow(int showID, [Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetPeopleFromShow(showID, where, new Sort(sort), limit); /// /// Get people's roles from a show. /// /// The slug of the show /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// A list of items that match every filters Task> GetPeopleFromShow(string showSlug, Expression> where = null, Sort sort = default, Pagination limit = default); /// /// Get people's roles from a show. /// /// The slug of the show /// A filter function /// A sort by method /// How many items to return and where to start /// A list of items that match every filters Task> GetPeopleFromShow(string showSlug, [Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetPeopleFromShow(showSlug, where, new Sort(sort), limit); /// /// Get people's roles from a person. /// /// The id of the person /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// A list of items that match every filters Task> GetRolesFromPeople(int id, Expression> where = null, Sort sort = default, Pagination limit = default); /// /// Get people's roles from a person. /// /// The id of the person /// A filter function /// A sort by method /// How many items to return and where to start /// A list of items that match every filters Task> GetRolesFromPeople(int id, [Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetRolesFromPeople(id, where, new Sort(sort), limit); /// /// Get people's roles from a person. /// /// The slug of the person /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// A list of items that match every filters Task> GetRolesFromPeople(string slug, Expression> where = null, Sort sort = default, Pagination limit = default); /// /// Get people's roles from a person. /// /// The slug of the person /// A filter function /// A sort by method /// How many items to return and where to start /// A list of items that match every filters Task> GetRolesFromPeople(string slug, [Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetRolesFromPeople(slug, where, new Sort(sort), limit); /// /// Setup relations between a show, a library and a collection /// /// The show's ID to setup relations with /// The library's ID to setup relations with (optional) /// The collection's ID to setup relations with (optional) /// A representing the asynchronous operation. Task AddShowLink(int showID, int? libraryID, int? collectionID); /// /// Setup relations between a show, a library and a collection /// /// The show to setup relations with /// The library to setup relations with (optional) /// The collection to setup relations with (optional) /// A representing the asynchronous operation. Task AddShowLink([NotNull] Show show, Library library, Collection collection); /// /// Get all resources with filters /// /// A filter function /// Sort information (sort order and sort by) /// How many items to return and where to start /// The type of resources to load /// A list of resources that match every filters Task> GetAll(Expression> where = null, Sort sort = default, Pagination limit = default) where T : class, IResource; /// /// Get all resources with filters /// /// A filter function /// A sort by function /// How many items to return and where to start /// The type of resources to load /// A list of resources that match every filters Task> GetAll([Optional] Expression> where, Expression> sort, Pagination limit = default) where T : class, IResource { return GetAll(where, new Sort(sort), limit); } /// /// Get the count of resources that match the filter /// /// A filter function /// The type of resources to load /// A list of resources that match every filters Task GetCount(Expression> where = null) where T : class, IResource; /// /// Search for a resource /// /// The search query /// The type of resources /// A list of 20 items that match the search query Task> Search(string query) where T : class, IResource; /// /// Create a new resource. /// /// The item to register /// The type of resource /// The resource registers and completed by database's information (related items and so on) Task Create([NotNull] T item) where T : class, IResource; /// /// Create a new resource if it does not exist already. If it does, the existing value is returned instead. /// /// The item to register /// The type of resource /// The newly created item or the existing value if it existed. Task CreateIfNotExists([NotNull] T item) where T : class, IResource; /// /// Edit a resource /// /// The resource to edit, it's ID can't change. /// Should old properties of the resource be discarded or should null values considered as not changed? /// The type of resources /// If the item is not found /// The resource edited and completed by database's information (related items and so on) Task Edit(T item, bool resetOld) where T : class, IResource; /// /// Delete a resource. /// /// The resource to delete /// The type of resource to delete /// If the item is not found /// A representing the asynchronous operation. Task Delete(T item) where T : class, IResource; /// /// Delete a resource by it's ID. /// /// The id of the resource to delete /// The type of resource to delete /// If the item is not found /// A representing the asynchronous operation. Task Delete(int id) where T : class, IResource; /// /// Delete a resource by it's slug. /// /// The slug of the resource to delete /// The type of resource to delete /// If the item is not found /// A representing the asynchronous operation. Task Delete(string slug) where T : class, IResource; } }