mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Adding more documentation
This commit is contained in:
parent
c7569691e2
commit
988135ec12
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using JetBrains.Annotations;
|
||||
using Kyoo.Models.Attributes;
|
||||
|
||||
namespace Kyoo.Models
|
||||
@ -59,12 +58,23 @@ namespace Kyoo.Models
|
||||
/// By default, the http path for this poster is returned from the public API.
|
||||
/// This can be disabled using the internal query flag.
|
||||
/// </summary>
|
||||
[SerializeAs("{HOST}/api/{_type}/{Slug}/poster")] public string Poster { get; set; }
|
||||
[UsedImplicitly] private string _type => Type == ItemType.Collection ? "collection" : "show";
|
||||
[SerializeAs("{HOST}/api/{Type}/{Slug}/poster")] public string Poster { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of this item (ether a collection, a show or a movie).
|
||||
/// </summary>
|
||||
public ItemType Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, empty <see cref="LibraryItem"/>.
|
||||
/// </summary>
|
||||
public LibraryItem() {}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="LibraryItem"/> from a show.
|
||||
/// </summary>
|
||||
/// <param name="show">The show that this library item should represent.</param>
|
||||
public LibraryItem(Show show)
|
||||
{
|
||||
ID = show.ID;
|
||||
@ -78,6 +88,10 @@ namespace Kyoo.Models
|
||||
Type = show.IsMovie ? ItemType.Movie : ItemType.Show;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="LibraryItem"/> from a collection
|
||||
/// </summary>
|
||||
/// <param name="collection">The collection that this library item should represent.</param>
|
||||
public LibraryItem(Collection collection)
|
||||
{
|
||||
ID = -collection.ID;
|
||||
@ -91,6 +105,9 @@ namespace Kyoo.Models
|
||||
Type = ItemType.Collection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An expression to create a <see cref="LibraryItem"/> representing a show.
|
||||
/// </summary>
|
||||
public static Expression<Func<Show, LibraryItem>> FromShow => x => new LibraryItem
|
||||
{
|
||||
ID = x.ID,
|
||||
@ -104,6 +121,9 @@ namespace Kyoo.Models
|
||||
Type = x.IsMovie ? ItemType.Movie : ItemType.Show
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// An expression to create a <see cref="LibraryItem"/> representing a collection.
|
||||
/// </summary>
|
||||
public static Expression<Func<Collection, LibraryItem>> FromCollection => x => new LibraryItem
|
||||
{
|
||||
ID = -x.ID,
|
||||
|
@ -3,30 +3,62 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A class representing a link between two resources.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Links should only be used on the data layer and not on other application code.
|
||||
/// </remarks>
|
||||
public class Link
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the first item of the link.
|
||||
/// The first item of the link should be the one to own the link.
|
||||
/// </summary>
|
||||
public int FirstID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the second item of this link
|
||||
/// The second item of the link should be the owned resource.
|
||||
/// </summary>
|
||||
public int SecondID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typeless <see cref="Link"/>.
|
||||
/// </summary>
|
||||
public Link() {}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typeless <see cref="Link"/> with two IDs.
|
||||
/// </summary>
|
||||
/// <param name="firstID">The ID of the first resource</param>
|
||||
/// <param name="secondID">The ID of the second resource</param>
|
||||
public Link(int firstID, int secondID)
|
||||
{
|
||||
FirstID = firstID;
|
||||
SecondID = secondID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typeless <see cref="Link"/> between two resources.
|
||||
/// </summary>
|
||||
/// <param name="first">The first resource</param>
|
||||
/// <param name="second">The second resource</param>
|
||||
public Link(IResource first, IResource second)
|
||||
{
|
||||
FirstID = first.ID;
|
||||
SecondID = second.ID;
|
||||
}
|
||||
|
||||
public static Link Create(IResource first, IResource second)
|
||||
{
|
||||
return new(first, second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typed link between two resources.
|
||||
/// This method can be used instead of the constructor to make use of generic parameters deduction.
|
||||
/// </summary>
|
||||
/// <param name="first">The first resource</param>
|
||||
/// <param name="second">The second resource</param>
|
||||
/// <typeparam name="T">The type of the first resource</typeparam>
|
||||
/// <typeparam name="T2">The type of the second resource</typeparam>
|
||||
/// <returns>A newly created typed link with both resources</returns>
|
||||
public static Link<T, T2> Create<T, T2>(T first, T2 second)
|
||||
where T : class, IResource
|
||||
where T2 : class, IResource
|
||||
@ -34,6 +66,16 @@ namespace Kyoo.Models
|
||||
return new(first, second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typed link between two resources without storing references to resources.
|
||||
/// This is the same as <see cref="Create{T,T2}"/> but this method does not set <see cref="Link{T1,T2}.First"/>
|
||||
/// and <see cref="Link{T1,T2}.Second"/> fields. Only IDs are stored and not references.
|
||||
/// </summary>
|
||||
/// <param name="first">The first resource</param>
|
||||
/// <param name="second">The second resource</param>
|
||||
/// <typeparam name="T">The type of the first resource</typeparam>
|
||||
/// <typeparam name="T2">The type of the second resource</typeparam>
|
||||
/// <returns>A newly created typed link with both resources</returns>
|
||||
public static Link<T, T2> UCreate<T, T2>(T first, T2 second)
|
||||
where T : class, IResource
|
||||
where T2 : class, IResource
|
||||
@ -41,6 +83,9 @@ namespace Kyoo.Models
|
||||
return new(first, second, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The expression to retrieve the unique ID of a Link. This is an aggregate of the two resources IDs.
|
||||
/// </summary>
|
||||
public static Expression<Func<Link, object>> PrimaryKey
|
||||
{
|
||||
get
|
||||
@ -50,16 +95,41 @@ namespace Kyoo.Models
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A strongly typed link between two resources.
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">The type of the first resource</typeparam>
|
||||
/// <typeparam name="T2">The type of the second resource</typeparam>
|
||||
public class Link<T1, T2> : Link
|
||||
where T1 : class, IResource
|
||||
where T2 : class, IResource
|
||||
{
|
||||
/// <summary>
|
||||
/// A reference of the first resource.
|
||||
/// </summary>
|
||||
public T1 First { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A reference to the second resource.
|
||||
/// </summary>
|
||||
public T2 Second { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, empty, typed <see cref="Link{T1,T2}"/>.
|
||||
/// </summary>
|
||||
public Link() {}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typed link with two resources.
|
||||
/// </summary>
|
||||
/// <param name="first">The first resource</param>
|
||||
/// <param name="second">The second resource</param>
|
||||
/// <param name="privateItems">
|
||||
/// True if no reference to resources should be kept, false otherwise.
|
||||
/// The default is false (references are kept).
|
||||
/// </param>
|
||||
public Link(T1 first, T2 second, bool privateItems = false)
|
||||
: base(first, second)
|
||||
{
|
||||
@ -69,10 +139,18 @@ namespace Kyoo.Models
|
||||
Second = second;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new typed link with IDs only.
|
||||
/// </summary>
|
||||
/// <param name="firstID">The ID of the first resource</param>
|
||||
/// <param name="secondID">The ID of the second resource</param>
|
||||
public Link(int firstID, int secondID)
|
||||
: base(firstID, secondID)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// The expression to retrieve the unique ID of a typed Link. This is an aggregate of the two resources IDs.
|
||||
/// </summary>
|
||||
public new static Expression<Func<Link<T1, T2>, object>> PrimaryKey
|
||||
{
|
||||
get
|
||||
|
@ -2,9 +2,16 @@ using Kyoo.Models.Attributes;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// ID and link of an item on an external provider.
|
||||
/// </summary>
|
||||
public class MetadataID
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique ID of this metadata. This is the equivalent of <see cref="IResource.ID"/>.
|
||||
/// </summary>
|
||||
[SerializeIgnore] public int ID { get; set; }
|
||||
|
||||
[SerializeIgnore] public int ProviderID { get; set; }
|
||||
public Provider Provider {get; set; }
|
||||
|
||||
|
@ -16,6 +16,8 @@ namespace Kyoo.Api
|
||||
{
|
||||
[Route("api/show")]
|
||||
[Route("api/shows")]
|
||||
[Route("api/movie")]
|
||||
[Route("api/movies")]
|
||||
[ApiController]
|
||||
[PartialPermission(nameof(ShowApi))]
|
||||
public class ShowApi : CrudApi<Show>
|
||||
|
Loading…
x
Reference in New Issue
Block a user