mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add from id in repository
This commit is contained in:
parent
49a1dad51e
commit
12f35fefc4
@ -94,11 +94,12 @@ namespace Kyoo.Abstractions.Controllers
|
||||
Sort<T>? sortBy = default);
|
||||
|
||||
/// <summary>
|
||||
/// Search for resources.
|
||||
/// Search for resources with the database.
|
||||
/// </summary>
|
||||
/// <param name="query">The query string.</param>
|
||||
/// <param name="include">The related fields to include.</param>
|
||||
/// <returns>A list of resources found</returns>
|
||||
Task<ICollection<T>> Search(string query);
|
||||
Task<ICollection<T>> Search(string query, Include<T>? include = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get every resources that match all filters
|
||||
@ -120,6 +121,14 @@ namespace Kyoo.Abstractions.Controllers
|
||||
/// <returns>How many resources matched that filter</returns>
|
||||
Task<int> GetCount(Expression<Func<T, bool>>? where = null);
|
||||
|
||||
/// <summary>
|
||||
/// Map a list of ids to a list of items (keep the order).
|
||||
/// </summary>
|
||||
/// <param name="ids">The list of items id.</param>
|
||||
/// <param name="include">The related fields to include.</param>
|
||||
/// <returns>A list of resources mapped from ids.</returns>
|
||||
Task<ICollection<T>> FromIds(IList<int> ids, Include<T>? include = default);
|
||||
|
||||
/// <summary>
|
||||
/// Create a new resource.
|
||||
/// </summary>
|
||||
|
@ -22,6 +22,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -52,13 +53,13 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<Collection>> Search(string query)
|
||||
public override async Task<ICollection<Collection>> Search(string query, Include<Collection>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.Collections
|
||||
.Where(_database.Like<Collection>(x => x.Name + " " + x.Slug, $"%{query}%"))
|
||||
.Take(20)
|
||||
).ToListAsync();
|
||||
AddIncludes(_database.Collections, include)
|
||||
.Where(_database.Like<Collection>(x => x.Name + " " + x.Slug, $"%{query}%"))
|
||||
.Take(20)
|
||||
).ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -22,6 +22,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -75,11 +76,10 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<Episode>> Search(string query)
|
||||
public override async Task<ICollection<Episode>> Search(string query, Include<Episode>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.Episodes
|
||||
.Where(x => x.EpisodeNumber != null || x.AbsoluteNumber != null)
|
||||
AddIncludes(_database.Episodes, include)
|
||||
.Where(_database.Like<Episode>(x => x.Name!, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
|
@ -22,6 +22,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -52,11 +53,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<LibraryItem>> Search(string query)
|
||||
public override async Task<ICollection<LibraryItem>> Search(string query, Include<LibraryItem>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.LibraryItems
|
||||
.Where(_database.Like<LibraryItem>(x => x.Name, $"%{query}%"))
|
||||
AddIncludes(_database.LibraryItems, include)
|
||||
.Where(_database.Like<LibraryItem>(x => x.Name, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
|
@ -351,16 +351,20 @@ namespace Kyoo.Core.Controllers
|
||||
.FirstOrDefaultAsync(where);
|
||||
}
|
||||
|
||||
public async Task<ICollection<T>> FromIds(IList<int> ids)
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<ICollection<T>> FromIds(IList<int> ids, Include<T>? include = default)
|
||||
{
|
||||
return await Database.Set<T>()
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
return (
|
||||
await AddIncludes(Database.Set<T>(), include)
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.ToListAsync()
|
||||
)
|
||||
.OrderBy(x => ids.IndexOf(x.Id))
|
||||
.ToListAsync();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract Task<ICollection<T>> Search(string query);
|
||||
public abstract Task<ICollection<T>> Search(string query, Include<T>? include = default);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual Task<ICollection<T>> GetAll(Expression<Func<T, bool>>? where = null,
|
||||
|
@ -21,6 +21,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -68,12 +69,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<Movie>> Search(string query)
|
||||
public override async Task<ICollection<Movie>> Search(string query, Include<Movie>? include = default)
|
||||
{
|
||||
query = $"%{query}%";
|
||||
return await Sort(
|
||||
_database.Movies
|
||||
.Where(_database.Like<Movie>(x => x.Name + " " + x.Slug, query))
|
||||
AddIncludes(_database.Movies, include)
|
||||
.Where(_database.Like<Movie>(x => x.Name + " " + x.Slug, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
|
@ -21,6 +21,7 @@ using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
|
||||
namespace Kyoo.Core.Controllers
|
||||
@ -38,7 +39,7 @@ namespace Kyoo.Core.Controllers
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ICollection<News>> Search(string query)
|
||||
public override Task<ICollection<News>> Search(string query, Include<News>? include = default)
|
||||
=> throw new InvalidOperationException();
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -23,6 +23,7 @@ using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -63,10 +64,10 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<People>> Search(string query)
|
||||
public override async Task<ICollection<People>> Search(string query, Include<People>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.People
|
||||
AddIncludes(_database.People, include)
|
||||
.Where(_database.Like<People>(x => x.Name, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
|
@ -23,6 +23,7 @@ using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Exceptions;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -69,11 +70,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<ICollection<Season>> Search(string query)
|
||||
public override async Task<ICollection<Season>> Search(string query, Include<Season>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.Seasons
|
||||
.Where(_database.Like<Season>(x => x.Name!, $"%{query}%"))
|
||||
AddIncludes(_database.Seasons, include)
|
||||
.Where(_database.Like<Season>(x => x.Name!, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
|
@ -21,6 +21,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -69,11 +70,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<Show>> Search(string query)
|
||||
public override async Task<ICollection<Show>> Search(string query, Include<Show>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.Shows
|
||||
.Where(_database.Like<Show>(x => x.Name + " " + x.Slug, $"%{query}%"))
|
||||
AddIncludes(_database.Shows, include)
|
||||
.Where(_database.Like<Show>(x => x.Name + " " + x.Slug, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
|
@ -21,6 +21,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -52,11 +53,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<Studio>> Search(string query)
|
||||
public override async Task<ICollection<Studio>> Search(string query, Include<Studio>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.Studios
|
||||
.Where(_database.Like<Studio>(x => x.Name, $"%{query}%"))
|
||||
AddIncludes(_database.Studios, include)
|
||||
.Where(_database.Like<Studio>(x => x.Name, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
|
@ -21,6 +21,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -51,11 +52,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<User>> Search(string query)
|
||||
public override async Task<ICollection<User>> Search(string query, Include<User>? include = default)
|
||||
{
|
||||
return await Sort(
|
||||
_database.Users
|
||||
.Where(_database.Like<User>(x => x.Username, $"%{query}%"))
|
||||
AddIncludes(_database.Users, include)
|
||||
.Where(_database.Like<User>(x => x.Username, $"%{query}%"))
|
||||
)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
|
Loading…
x
Reference in New Issue
Block a user