mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Support collections/id/items via dapper
This commit is contained in:
parent
5f177e9338
commit
29314d473f
@ -20,7 +20,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
@ -66,9 +65,15 @@ namespace Kyoo.Core.Controllers
|
|||||||
if (items[0] is Show show && show.Id != 0)
|
if (items[0] is Show show && show.Id != 0)
|
||||||
return show;
|
return show;
|
||||||
if (items[1] is Movie movie && movie.Id != 0)
|
if (items[1] is Movie movie && movie.Id != 0)
|
||||||
|
{
|
||||||
|
movie.Id = -movie.Id;
|
||||||
return movie;
|
return movie;
|
||||||
|
}
|
||||||
if (items[2] is Collection collection && collection.Id != 0)
|
if (items[2] is Collection collection && collection.Id != 0)
|
||||||
|
{
|
||||||
|
collection.Id += 10_000;
|
||||||
return collection;
|
return collection;
|
||||||
|
}
|
||||||
throw new InvalidDataException();
|
throw new InvalidDataException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,27 +82,48 @@ namespace Kyoo.Core.Controllers
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
public async Task<ICollection<ILibraryItem>> GetAllOfCollection(
|
public async Task<ICollection<ILibraryItem>> GetAllOfCollection(
|
||||||
Expression<Func<Collection, bool>> selector,
|
int collectionId,
|
||||||
Expression<Func<ILibraryItem, bool>>? where = null,
|
Filter<ILibraryItem>? filter = default,
|
||||||
Sort<ILibraryItem>? sort = default,
|
Sort<ILibraryItem>? sort = default,
|
||||||
Pagination? limit = default,
|
Include<ILibraryItem>? include = default,
|
||||||
Include<ILibraryItem>? include = default)
|
Pagination? limit = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// language=PostgreSQL
|
||||||
// return await ApplyFilters(
|
FormattableString sql = $"""
|
||||||
// _database.LibraryItems
|
select
|
||||||
// .Where(item =>
|
s.*,
|
||||||
// _database.Movies
|
m.*
|
||||||
// .Where(x => x.Id == -item.Id)
|
/* includes */
|
||||||
// .Any(x => x.Collections!.AsQueryable().Any(selector))
|
from (
|
||||||
// || _database.Shows
|
select
|
||||||
// .Where(x => x.Id == item.Id)
|
* -- Show
|
||||||
// .Any(x => x.Collections!.AsQueryable().Any(selector))
|
from
|
||||||
// ),
|
shows
|
||||||
// where,
|
inner join link_collection_show as ls on ls.show_id = id and ls.collection_id = {collectionId}
|
||||||
// sort,
|
) as s
|
||||||
// limit,
|
full outer join (
|
||||||
// include);
|
select
|
||||||
|
* -- Movie
|
||||||
|
from
|
||||||
|
movies
|
||||||
|
inner join link_collection_movie as lm on lm.movie_id = id and lm.collection_id = {collectionId}
|
||||||
|
) as m on false
|
||||||
|
""";
|
||||||
|
|
||||||
|
return await Database.Query<ILibraryItem>(
|
||||||
|
sql,
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
{ "s", typeof(Show) },
|
||||||
|
{ "m", typeof(Movie) },
|
||||||
|
},
|
||||||
|
Mapper,
|
||||||
|
(id) => Get(id),
|
||||||
|
include,
|
||||||
|
filter,
|
||||||
|
sort ?? new Sort<ILibraryItem>.Default(),
|
||||||
|
limit ?? new()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,17 +144,21 @@ namespace Kyoo.Core.Api
|
|||||||
[FromQuery] Pagination pagination,
|
[FromQuery] Pagination pagination,
|
||||||
[FromQuery] Include<ILibraryItem>? fields)
|
[FromQuery] Include<ILibraryItem>? fields)
|
||||||
{
|
{
|
||||||
// ICollection<ILibraryItem> resources = await _items.GetAllOfCollection(
|
int collectionId = await identifier.Match(
|
||||||
// identifier.IsSame<Collection>(),
|
id => Task.FromResult(id),
|
||||||
// filter,
|
async slug => (await _libraryManager.Collections.Get(slug)).Id
|
||||||
// sortBy == new Sort<ILibraryItem>.Default() ? new Sort<ILibraryItem>.By(nameof(Movie.AirDate)) : sortBy,
|
);
|
||||||
// pagination,
|
ICollection<ILibraryItem> resources = await _items.GetAllOfCollection(
|
||||||
// fields
|
collectionId,
|
||||||
// );
|
filter,
|
||||||
|
sortBy == new Sort<ILibraryItem>.Default() ? new Sort<ILibraryItem>.By(nameof(Movie.AirDate)) : sortBy,
|
||||||
|
fields,
|
||||||
|
pagination
|
||||||
|
);
|
||||||
|
|
||||||
// if (!resources.Any() && await _libraryManager.Collections.GetOrDefault(identifier.IsSame<Collection>()) == null)
|
if (!resources.Any() && await _libraryManager.Collections.GetOrDefault(identifier.IsSame<Collection>()) == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
// return Page(resources, pagination.Limit);
|
return Page(resources, pagination.Limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -88,7 +88,7 @@ public class SearchManager : ISearchManager
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Since library items's ID are still ints mapped from real items ids, we must map it here to match the db's value.
|
// Since library items's ID are still ints mapped from real items ids, we must map it here to match the db's value.
|
||||||
// Look at the items Migration's sql to understand where magic numbers come from.
|
// Look at the LibraryItemRepository's Mapper to understand what those magic numbers are.
|
||||||
List<int> ids = res.Hits.Select(x => x.Kind switch
|
List<int> ids = res.Hits.Select(x => x.Kind switch
|
||||||
{
|
{
|
||||||
nameof(Show) => x.Id,
|
nameof(Show) => x.Id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user