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