mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-20 09:06:38 +00:00
add ability to mark studios, genres and people as favorites
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Querying;
|
||||
@@ -196,6 +197,28 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the favorite.
|
||||
/// </summary>
|
||||
/// <param name="getItem">The get item.</param>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected async Task MarkFavorite(Func<Task<TItemType>> getItem, Guid userId, bool isFavorite)
|
||||
{
|
||||
var user = UserManager.GetUserById(userId);
|
||||
|
||||
var item = await getItem().ConfigureAwait(false);
|
||||
|
||||
// Get the user data for this item
|
||||
var data = await UserManager.GetUserData(user.Id, item.UserDataId).ConfigureAwait(false);
|
||||
|
||||
// Set favorite status
|
||||
data.IsFavorite = isFavorite;
|
||||
|
||||
await UserManager.SaveUserData(user.Id, item.UserDataId, data, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using ServiceStack.ServiceHost;
|
||||
using System;
|
||||
@@ -18,6 +19,44 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
{
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/FavoriteGenres/{Name}", "POST")]
|
||||
[Api(Description = "Marks a genre as a favorite")]
|
||||
public class MarkFavoriteGenre : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/FavoriteGenres/{Name}", "DELETE")]
|
||||
[Api(Description = "Unmarks a genre as a favorite")]
|
||||
public class UnmarkFavoriteGenre : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class GenresService
|
||||
/// </summary>
|
||||
@@ -40,6 +79,28 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(MarkFavoriteGenre request)
|
||||
{
|
||||
var task = MarkFavorite(() => LibraryManager.GetGenre(request.Name), request.UserId, true);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(UnmarkFavoriteGenre request)
|
||||
{
|
||||
var task = MarkFavorite(() => LibraryManager.GetGenre(request.Name), request.UserId, false);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all items.
|
||||
/// </summary>
|
||||
|
||||
@@ -23,6 +23,44 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
public string PersonTypes { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/FavoritePersons/{Name}", "POST")]
|
||||
[Api(Description = "Marks a person as a favorite")]
|
||||
public class MarkFavoritePerson : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/FavoritePersons/{Name}", "DELETE")]
|
||||
[Api(Description = "Unmarks a person as a favorite")]
|
||||
public class UnmarkFavoritePerson : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class PersonsService
|
||||
/// </summary>
|
||||
@@ -45,6 +83,28 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(MarkFavoritePerson request)
|
||||
{
|
||||
var task = MarkFavorite(() => LibraryManager.GetPerson(request.Name), request.UserId, true);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(UnmarkFavoritePerson request)
|
||||
{
|
||||
var task = MarkFavorite(() => LibraryManager.GetPerson(request.Name), request.UserId, false);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all items.
|
||||
/// </summary>
|
||||
|
||||
@@ -18,6 +18,44 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
{
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/FavoriteStudios/{Name}", "POST")]
|
||||
[Api(Description = "Marks a studio as a favorite")]
|
||||
public class MarkFavoriteStudio : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/FavoriteStudios/{Name}", "DELETE")]
|
||||
[Api(Description = "Unmarks a studio as a favorite")]
|
||||
public class UnmarkFavoriteStudio : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class StudiosService
|
||||
/// </summary>
|
||||
@@ -40,6 +78,28 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(MarkFavoriteStudio request)
|
||||
{
|
||||
var task = MarkFavorite(() => LibraryManager.GetStudio(request.Name), request.UserId, true);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(UnmarkFavoriteStudio request)
|
||||
{
|
||||
var task = MarkFavorite(() => LibraryManager.GetStudio(request.Name), request.UserId, false);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all items.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user