From b3cb8fda22337e22d6d4ee45d5ec6e9cf69be7fa Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 12 Apr 2013 20:42:51 -0400 Subject: add ability to mark studios, genres and people as favorites --- .../UserLibrary/BaseItemsByNameService.cs | 25 ++++++++- MediaBrowser.Api/UserLibrary/GenresService.cs | 63 +++++++++++++++++++++- MediaBrowser.Api/UserLibrary/PersonsService.cs | 60 +++++++++++++++++++++ MediaBrowser.Api/UserLibrary/StudiosService.cs | 60 +++++++++++++++++++++ 4 files changed, 206 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Api/UserLibrary') diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 583f7460d..6801e14f0 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -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; } + + /// + /// Marks the favorite. + /// + /// The get item. + /// The user id. + /// if set to true [is favorite]. + /// Task. + protected async Task MarkFavorite(Func> 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); + } } /// diff --git a/MediaBrowser.Api/UserLibrary/GenresService.cs b/MediaBrowser.Api/UserLibrary/GenresService.cs index 13c441c63..54561f400 100644 --- a/MediaBrowser.Api/UserLibrary/GenresService.cs +++ b/MediaBrowser.Api/UserLibrary/GenresService.cs @@ -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 + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [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 + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public string Name { get; set; } + } + /// /// Class GenresService /// @@ -40,6 +79,28 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(result); } + /// + /// Posts the specified request. + /// + /// The request. + public void Post(MarkFavoriteGenre request) + { + var task = MarkFavorite(() => LibraryManager.GetGenre(request.Name), request.UserId, true); + + Task.WaitAll(task); + } + + /// + /// Deletes the specified request. + /// + /// The request. + public void Delete(UnmarkFavoriteGenre request) + { + var task = MarkFavorite(() => LibraryManager.GetGenre(request.Name), request.UserId, false); + + Task.WaitAll(task); + } + /// /// Gets all items. /// diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index 020c373a0..4253ddc80 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -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 + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [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 + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public string Name { get; set; } + } + /// /// Class PersonsService /// @@ -45,6 +83,28 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(result); } + /// + /// Posts the specified request. + /// + /// The request. + public void Post(MarkFavoritePerson request) + { + var task = MarkFavorite(() => LibraryManager.GetPerson(request.Name), request.UserId, true); + + Task.WaitAll(task); + } + + /// + /// Deletes the specified request. + /// + /// The request. + public void Delete(UnmarkFavoritePerson request) + { + var task = MarkFavorite(() => LibraryManager.GetPerson(request.Name), request.UserId, false); + + Task.WaitAll(task); + } + /// /// Gets all items. /// diff --git a/MediaBrowser.Api/UserLibrary/StudiosService.cs b/MediaBrowser.Api/UserLibrary/StudiosService.cs index 219475704..24f09c5ef 100644 --- a/MediaBrowser.Api/UserLibrary/StudiosService.cs +++ b/MediaBrowser.Api/UserLibrary/StudiosService.cs @@ -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 + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [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 + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] + public string Name { get; set; } + } + /// /// Class StudiosService /// @@ -40,6 +78,28 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(result); } + /// + /// Posts the specified request. + /// + /// The request. + public void Post(MarkFavoriteStudio request) + { + var task = MarkFavorite(() => LibraryManager.GetStudio(request.Name), request.UserId, true); + + Task.WaitAll(task); + } + + /// + /// Deletes the specified request. + /// + /// The request. + public void Delete(UnmarkFavoriteStudio request) + { + var task = MarkFavorite(() => LibraryManager.GetStudio(request.Name), request.UserId, false); + + Task.WaitAll(task); + } + /// /// Gets all items. /// -- cgit v1.2.3