mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fix fields serialization
This commit is contained in:
parent
c7db07f7ba
commit
86427cf6ef
@ -17,12 +17,11 @@
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
|
||||
namespace Kyoo.Abstractions.Models.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// The targeted relation can be loaded via a call to <see cref="ILibraryManager.Load"/>.
|
||||
/// The targeted relation can be loaded.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LoadableRelationAttribute : Attribute
|
||||
|
@ -84,7 +84,7 @@ namespace Kyoo.Abstractions.Models
|
||||
[SerializeIgnore] public int ShowId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The show that contains this episode. This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
|
||||
/// The show that contains this episode.
|
||||
/// </summary>
|
||||
[LoadableRelation(nameof(ShowId))] public Show? Show { get; set; }
|
||||
|
||||
@ -95,7 +95,6 @@ namespace Kyoo.Abstractions.Models
|
||||
|
||||
/// <summary>
|
||||
/// The season that contains this episode.
|
||||
/// This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can be null if the season is unknown and the episode is only identified
|
||||
|
@ -25,8 +25,15 @@ using Kyoo.Abstractions.Models.Attributes;
|
||||
|
||||
namespace Kyoo.Abstractions.Models.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// The aditional fields to include in the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type related to the new fields</typeparam>
|
||||
public class Include<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The aditional fields to include in the result.
|
||||
/// </summary>
|
||||
public ICollection<string> Fields { get; private init; } = ArraySegment<string>.Empty;
|
||||
|
||||
public static Include<T> From(string? fields)
|
||||
|
@ -129,18 +129,18 @@ namespace Kyoo.Core.Controllers
|
||||
// Sort<PeopleRole>? sort = default,
|
||||
// Pagination? limit = default)
|
||||
// {
|
||||
// ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles
|
||||
// .Where(x => x.ShowID == showID)
|
||||
// .Include(x => x.People),
|
||||
// x => x.People.Name,
|
||||
// where,
|
||||
// sort,
|
||||
// limit);
|
||||
// if (!people.Any() && await _shows.Value.GetOrDefault(showID) == null)
|
||||
// throw new ItemNotFoundException();
|
||||
// foreach (PeopleRole role in people)
|
||||
// role.ForPeople = true;
|
||||
// return people;
|
||||
// ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles
|
||||
// .Where(x => x.ShowID == showID)
|
||||
// .Include(x => x.People),
|
||||
// x => x.People.Name,
|
||||
// where,
|
||||
// sort,
|
||||
// limit);
|
||||
// if (!people.Any() && await _shows.Value.GetOrDefault(showID) == null)
|
||||
// throw new ItemNotFoundException();
|
||||
// foreach (PeopleRole role in people)
|
||||
// role.ForPeople = true;
|
||||
// return people;
|
||||
// }
|
||||
|
||||
// /// <inheritdoc />
|
||||
|
@ -37,6 +37,7 @@ public class IncludeBinder : IModelBinder
|
||||
object include = bindingContext.ModelType.GetMethod(nameof(Include<object>.From))!
|
||||
.Invoke(null, new object?[] { fields.FirstValue })!;
|
||||
bindingContext.Result = ModelBindingResult.Success(include);
|
||||
bindingContext.HttpContext.Items["fields"] = ((dynamic)include).Fields;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
|
@ -58,9 +58,6 @@ namespace Kyoo.Core.Api
|
||||
{
|
||||
property.ShouldSerialize = _ =>
|
||||
{
|
||||
string resType = (string)_httpContextAccessor.HttpContext!.Items["ResourceType"]!;
|
||||
if (member.DeclaringType!.Name != resType)
|
||||
return false;
|
||||
ICollection<string> fields = (ICollection<string>)_httpContextAccessor.HttpContext!.Items["fields"]!;
|
||||
return fields.Contains(member.Name);
|
||||
};
|
||||
|
@ -82,7 +82,7 @@ namespace Kyoo.Tests.Database
|
||||
}
|
||||
|
||||
public IRepository<T> GetRepository<T>()
|
||||
where T: class, IResource
|
||||
where T : class, IResource
|
||||
{
|
||||
return _repositories.First(x => x.RepositoryType == typeof(T)) as IRepository<T>;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user