add ability to mark studios, genres and people as favorites
This commit is contained in:
parent
b721aab2ba
commit
b3cb8fda22
|
@ -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>
|
||||
|
|
|
@ -417,7 +417,6 @@ namespace MediaBrowser.WebDashboard.Api
|
|||
"http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js",
|
||||
"http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js",
|
||||
"http://vjs.zencdn.net/c/video.js",
|
||||
"thirdparty/jplayer/jquery.jplayer.min.js" + versionString,
|
||||
"scripts/all.js" + versionString
|
||||
};
|
||||
|
||||
|
|
|
@ -1671,7 +1671,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Updates a user's favorite status for an item and returns the updated UserItemData object.
|
||||
* Updates a user's favorite status for an item.
|
||||
* @param {String} userId
|
||||
* @param {String} itemId
|
||||
* @param {Boolean} isFavorite
|
||||
|
@ -1723,6 +1723,87 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a user's favorite status for a person.
|
||||
* @param {String} userId
|
||||
* @param {String} name
|
||||
* @param {Boolean} isFavorite
|
||||
*/
|
||||
self.updateFavoritePersonStatus = function (userId, name, isFavorite) {
|
||||
|
||||
if (!userId) {
|
||||
throw new Error("null userId");
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
throw new Error("null name");
|
||||
}
|
||||
|
||||
var url = self.getUrl("Users/" + userId + "/FavoritePersons/" + name);
|
||||
|
||||
var method = isFavorite ? "POST" : "DELETE";
|
||||
|
||||
return self.ajax({
|
||||
type: method,
|
||||
url: url,
|
||||
dataType: "json"
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a user's favorite status for a genre.
|
||||
* @param {String} userId
|
||||
* @param {String} name
|
||||
* @param {Boolean} isFavorite
|
||||
*/
|
||||
self.updateFavoriteGenreStatus = function (userId, name, isFavorite) {
|
||||
|
||||
if (!userId) {
|
||||
throw new Error("null userId");
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
throw new Error("null name");
|
||||
}
|
||||
|
||||
var url = self.getUrl("Users/" + userId + "/FavoriteGenre/" + name);
|
||||
|
||||
var method = isFavorite ? "POST" : "DELETE";
|
||||
|
||||
return self.ajax({
|
||||
type: method,
|
||||
url: url,
|
||||
dataType: "json"
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a user's favorite status for a studio.
|
||||
* @param {String} userId
|
||||
* @param {String} name
|
||||
* @param {Boolean} isFavorite
|
||||
*/
|
||||
self.updateFavoriteStudioStatus = function (userId, name, isFavorite) {
|
||||
|
||||
if (!userId) {
|
||||
throw new Error("null userId");
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
throw new Error("null name");
|
||||
}
|
||||
|
||||
var url = self.getUrl("Users/" + userId + "/FavoriteStudios/" + name);
|
||||
|
||||
var method = isFavorite ? "POST" : "DELETE";
|
||||
|
||||
return self.ajax({
|
||||
type: method,
|
||||
url: url,
|
||||
dataType: "json"
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears a user's personal rating for an item
|
||||
* @param {String} userId
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.73" targetFramework="net45" />
|
||||
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.74" targetFramework="net45" />
|
||||
<package id="ServiceStack.Common" version="3.9.43" targetFramework="net45" />
|
||||
<package id="ServiceStack.Text" version="3.9.43" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user