diff --git a/back/src/Kyoo.Abstractions/Models/Attributes/LoadableRelationAttribute.cs b/back/src/Kyoo.Abstractions/Models/Attributes/LoadableRelationAttribute.cs index 0a0a9672..c530b0fb 100644 --- a/back/src/Kyoo.Abstractions/Models/Attributes/LoadableRelationAttribute.cs +++ b/back/src/Kyoo.Abstractions/Models/Attributes/LoadableRelationAttribute.cs @@ -17,12 +17,11 @@ // along with Kyoo. If not, see . using System; -using Kyoo.Abstractions.Controllers; namespace Kyoo.Abstractions.Models.Attributes { /// - /// The targeted relation can be loaded via a call to . + /// The targeted relation can be loaded. /// [AttributeUsage(AttributeTargets.Property)] public class LoadableRelationAttribute : Attribute diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs index 40ddfedf..5a009bf7 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs @@ -84,7 +84,7 @@ namespace Kyoo.Abstractions.Models [SerializeIgnore] public int ShowId { get; set; } /// - /// The show that contains this episode. This must be explicitly loaded via a call to . + /// The show that contains this episode. /// [LoadableRelation(nameof(ShowId))] public Show? Show { get; set; } @@ -95,7 +95,6 @@ namespace Kyoo.Abstractions.Models /// /// The season that contains this episode. - /// This must be explicitly loaded via a call to . /// /// /// This can be null if the season is unknown and the episode is only identified diff --git a/back/src/Kyoo.Abstractions/Models/Utils/Include.cs b/back/src/Kyoo.Abstractions/Models/Utils/Include.cs index 36a44360..045ac2cc 100644 --- a/back/src/Kyoo.Abstractions/Models/Utils/Include.cs +++ b/back/src/Kyoo.Abstractions/Models/Utils/Include.cs @@ -25,8 +25,15 @@ using Kyoo.Abstractions.Models.Attributes; namespace Kyoo.Abstractions.Models.Utils; +/// +/// The aditional fields to include in the result. +/// +/// The type related to the new fields public class Include { + /// + /// The aditional fields to include in the result. + /// public ICollection Fields { get; private init; } = ArraySegment.Empty; public static Include From(string? fields) diff --git a/back/src/Kyoo.Core/Controllers/Repositories/PeopleRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/PeopleRepository.cs index 004d6e9f..e01890bb 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/PeopleRepository.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/PeopleRepository.cs @@ -129,18 +129,18 @@ namespace Kyoo.Core.Controllers // Sort? sort = default, // Pagination? limit = default) // { - // ICollection 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 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; // } // /// diff --git a/back/src/Kyoo.Core/Views/Helper/IncludeBinder.cs b/back/src/Kyoo.Core/Views/Helper/IncludeBinder.cs index 2be993ce..4ce25b97 100644 --- a/back/src/Kyoo.Core/Views/Helper/IncludeBinder.cs +++ b/back/src/Kyoo.Core/Views/Helper/IncludeBinder.cs @@ -37,6 +37,7 @@ public class IncludeBinder : IModelBinder object include = bindingContext.ModelType.GetMethod(nameof(Include.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) diff --git a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs index bda5db67..eeb71cc9 100644 --- a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs +++ b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs @@ -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 fields = (ICollection)_httpContextAccessor.HttpContext!.Items["fields"]!; return fields.Contains(member.Name); }; diff --git a/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs b/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs index 0504aeea..f2aebc4d 100644 --- a/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs +++ b/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs @@ -82,7 +82,7 @@ namespace Kyoo.Tests.Database } public IRepository GetRepository() - where T: class, IResource + where T : class, IResource { return _repositories.First(x => x.RepositoryType == typeof(T)) as IRepository; }