mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fix library item issue
This commit is contained in:
parent
d394c390f7
commit
938ccd9215
@ -327,7 +327,7 @@ namespace Kyoo.Abstractions.Controllers
|
||||
/// <summary>
|
||||
/// A repository to handle library items (A wrapper around shows and collections).
|
||||
/// </summary>
|
||||
public interface ILibraryItemRepository : IRepository<ILibraryItem> { }
|
||||
public interface ILibraryItemRepository : IRepository<LibraryItem> { }
|
||||
|
||||
/// <summary>
|
||||
/// A repository for collections
|
||||
|
@ -45,7 +45,7 @@ namespace Kyoo.Abstractions.Models
|
||||
Collection
|
||||
}
|
||||
|
||||
public class LibraryItem : IResource, ILibraryItem, IThumbnails, IMetadata
|
||||
public class LibraryItem : IResource, IThumbnails, IMetadata
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Id { get; set; }
|
||||
@ -124,7 +124,9 @@ namespace Kyoo.Abstractions.Models
|
||||
/// </summary>
|
||||
public string? Trailer { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Is the item a collection, a movie or a show?
|
||||
/// </summary>
|
||||
public ItemKind Kind { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -149,31 +151,4 @@ namespace Kyoo.Abstractions.Models
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type union between <see cref="Show"/> and <see cref="Collection"/>.
|
||||
/// This is used to list content put inside a library.
|
||||
/// </summary>
|
||||
public interface ILibraryItem : IResource
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the item a collection, a movie or a show?
|
||||
/// </summary>
|
||||
public ItemKind Kind { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The title of this show.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The summary of this show.
|
||||
/// </summary>
|
||||
public string? Overview { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The date this movie aired.
|
||||
/// </summary>
|
||||
public DateTime? AirDate { get; }
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The items that matched the search.
|
||||
/// </summary>
|
||||
public ICollection<ILibraryItem> Items { get; init; }
|
||||
public ICollection<LibraryItem> Items { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The movies that matched the search.
|
||||
|
@ -74,7 +74,7 @@ namespace Kyoo.Core.Controllers
|
||||
public LibraryManager(IEnumerable<IBaseRepository> repositories)
|
||||
{
|
||||
_repositories = repositories.ToArray();
|
||||
LibraryItemRepository = GetRepository<ILibraryItem>() as ILibraryItemRepository;
|
||||
LibraryItemRepository = GetRepository<LibraryItem>() as ILibraryItemRepository;
|
||||
CollectionRepository = GetRepository<Collection>() as ICollectionRepository;
|
||||
MovieRepository = GetRepository<Movie>() as IMovieRepository;
|
||||
ShowRepository = GetRepository<Show>() as IShowRepository;
|
||||
|
@ -32,7 +32,7 @@ namespace Kyoo.Core.Controllers
|
||||
/// <summary>
|
||||
/// A local repository to handle library items.
|
||||
/// </summary>
|
||||
public class LibraryItemRepository : LocalRepository<ILibraryItem>, ILibraryItemRepository
|
||||
public class LibraryItemRepository : LocalRepository<LibraryItem>, ILibraryItemRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// The database handle
|
||||
@ -40,7 +40,7 @@ namespace Kyoo.Core.Controllers
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Sort<ILibraryItem> DefaultSort => new Sort<ILibraryItem>.By(x => x.Name);
|
||||
protected override Sort<LibraryItem> DefaultSort => new Sort<LibraryItem>.By(x => x.Name);
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="ILibraryItemRepository"/>.
|
||||
@ -54,26 +54,26 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ILibraryItem> GetOrDefault(int id)
|
||||
public override async Task<LibraryItem> GetOrDefault(int id)
|
||||
{
|
||||
return await _database.LibraryItems.SingleOrDefaultAsync(x => x.Id == id).Then(SetBackingImage);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ILibraryItem> GetOrDefault(string slug)
|
||||
public override async Task<LibraryItem> GetOrDefault(string slug)
|
||||
{
|
||||
return await _database.LibraryItems.SingleOrDefaultAsync(x => x.Slug == slug).Then(SetBackingImage);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ILibraryItem> GetOrDefault(Expression<Func<ILibraryItem, bool>> where, Sort<ILibraryItem> sortBy = default)
|
||||
public override async Task<LibraryItem> GetOrDefault(Expression<Func<LibraryItem, bool>> where, Sort<LibraryItem> sortBy = default)
|
||||
{
|
||||
return await Sort(_database.LibraryItems, sortBy).FirstOrDefaultAsync(where).Then(SetBackingImage);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<ILibraryItem>> GetAll(Expression<Func<ILibraryItem, bool>> where = null,
|
||||
Sort<ILibraryItem> sort = default,
|
||||
public override async Task<ICollection<LibraryItem>> GetAll(Expression<Func<LibraryItem, bool>> where = null,
|
||||
Sort<LibraryItem> sort = default,
|
||||
Pagination limit = default)
|
||||
{
|
||||
return (await ApplyFilters(_database.LibraryItems, where, sort, limit))
|
||||
@ -81,16 +81,16 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<int> GetCount(Expression<Func<ILibraryItem, bool>> where = null)
|
||||
public override Task<int> GetCount(Expression<Func<LibraryItem, bool>> where = null)
|
||||
{
|
||||
IQueryable<ILibraryItem> query = _database.LibraryItems;
|
||||
IQueryable<LibraryItem> query = _database.LibraryItems;
|
||||
if (where != null)
|
||||
query = query.Where(where);
|
||||
return query.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<ILibraryItem>> Search(string query)
|
||||
public override async Task<ICollection<LibraryItem>> Search(string query)
|
||||
{
|
||||
return (await Sort(
|
||||
_database.LibraryItems
|
||||
@ -103,19 +103,19 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ILibraryItem> Create(ILibraryItem obj)
|
||||
public override Task<LibraryItem> Create(LibraryItem obj)
|
||||
=> throw new InvalidOperationException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ILibraryItem> CreateIfNotExists(ILibraryItem obj)
|
||||
public override Task<LibraryItem> CreateIfNotExists(LibraryItem obj)
|
||||
=> throw new InvalidOperationException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ILibraryItem> Edit(ILibraryItem edited)
|
||||
public override Task<LibraryItem> Edit(LibraryItem edited)
|
||||
=> throw new InvalidOperationException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ILibraryItem> Patch(int id, Func<ILibraryItem, Task<bool>> patch)
|
||||
public override Task<LibraryItem> Patch(int id, Func<LibraryItem, Task<bool>> patch)
|
||||
=> throw new InvalidOperationException();
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -127,7 +127,7 @@ namespace Kyoo.Core.Controllers
|
||||
=> throw new InvalidOperationException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task Delete(ILibraryItem obj)
|
||||
public override Task Delete(LibraryItem obj)
|
||||
=> throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ namespace Kyoo.Core.Controllers
|
||||
{
|
||||
if (obj is not IThumbnails thumbs)
|
||||
return;
|
||||
string type = obj is ILibraryItem item
|
||||
string type = obj is LibraryItem item
|
||||
? item.Kind.ToString().ToLowerInvariant()
|
||||
: typeof(T).Name.ToLowerInvariant();
|
||||
|
||||
|
@ -77,14 +77,14 @@ namespace Kyoo.Core.Api
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult<Page<ILibraryItem>>> GetAll(
|
||||
public async Task<ActionResult<Page<LibraryItem>>> GetAll(
|
||||
[FromQuery] string sortBy,
|
||||
[FromQuery] Dictionary<string, string> where,
|
||||
[FromQuery] Pagination pagination)
|
||||
{
|
||||
ICollection<ILibraryItem> resources = await _libraryItems.GetAll(
|
||||
ApiHelper.ParseWhere<ILibraryItem>(where),
|
||||
Sort<ILibraryItem>.From(sortBy),
|
||||
ICollection<LibraryItem> resources = await _libraryItems.GetAll(
|
||||
ApiHelper.ParseWhere<LibraryItem>(where),
|
||||
Sort<LibraryItem>.From(sortBy),
|
||||
pagination
|
||||
);
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace Kyoo.Core.Api
|
||||
{
|
||||
Query = query,
|
||||
Collections = await _libraryManager.Search<Collection>(query),
|
||||
Items = await _libraryManager.Search<ILibraryItem>(query),
|
||||
Items = await _libraryManager.Search<LibraryItem>(query),
|
||||
Movies = await _libraryManager.Search<Movie>(query),
|
||||
Shows = await _libraryManager.Search<Show>(query),
|
||||
Episodes = await _libraryManager.Search<Episode>(query),
|
||||
@ -134,9 +134,9 @@ namespace Kyoo.Core.Api
|
||||
[Permission(nameof(Show), Kind.Read)]
|
||||
[ApiDefinition("Items")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public Task<ICollection<ILibraryItem>> SearchItems(string query)
|
||||
public Task<ICollection<LibraryItem>> SearchItems(string query)
|
||||
{
|
||||
return _libraryManager.Search<ILibraryItem>(query);
|
||||
return _libraryManager.Search<LibraryItem>(query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user