Get/Set DisplayPreferences separately through the api
This commit is contained in:
parent
03a36d4628
commit
1bf4b6110d
100
MediaBrowser.Api/DisplayPreferencesService.cs
Normal file
100
MediaBrowser.Api/DisplayPreferencesService.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using ServiceStack.ServiceHost;
|
||||
using ServiceStack.Text.Controller;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UpdateDisplayPreferences
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/DisplayPreferences/{Id}", "POST")]
|
||||
[Api(("Updates a user's display preferences for an item"))]
|
||||
public class UpdateDisplayPreferences : DisplayPreferences, IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public Guid Id { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Users/{UserId}/DisplayPreferences/{Id}", "GET")]
|
||||
[Api(("Gets a user's display preferences for an item"))]
|
||||
public class GetDisplayPreferences : IReturn<DisplayPreferences>
|
||||
{
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public Guid Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class DisplayPreferencesService
|
||||
/// </summary>
|
||||
public class DisplayPreferencesService : BaseApiService
|
||||
{
|
||||
/// <summary>
|
||||
/// The _user manager
|
||||
/// </summary>
|
||||
private readonly IUserManager _userManager;
|
||||
/// <summary>
|
||||
/// The _json serializer
|
||||
/// </summary>
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DisplayPreferencesService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="jsonSerializer">The json serializer.</param>
|
||||
public DisplayPreferencesService(IUserManager userManager, IJsonSerializer jsonSerializer)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public object Get(GetDisplayPreferences request)
|
||||
{
|
||||
var task = _userManager.GetDisplayPreferences(request.UserId, request.Id);
|
||||
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(UpdateDisplayPreferences request)
|
||||
{
|
||||
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
|
||||
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
|
||||
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
|
||||
var userId = new Guid(pathInfo.GetArgumentValue<string>(1));
|
||||
var displayPreferencesId = new Guid(pathInfo.GetArgumentValue<string>(3));
|
||||
|
||||
var user = _userManager.GetUserById(userId);
|
||||
|
||||
// Serialize to json and then back so that the core doesn't see the request dto type
|
||||
var displayPreferences = _jsonSerializer.DeserializeFromString<DisplayPreferences>(_jsonSerializer.SerializeToString(request));
|
||||
|
||||
var task = _userManager.SaveDisplayPreferences(user.Id, displayPreferencesId, displayPreferences, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,6 +62,7 @@
|
|||
<Link>Properties\SharedVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="BaseApiService.cs" />
|
||||
<Compile Include="DisplayPreferencesService.cs" />
|
||||
<Compile Include="EnvironmentService.cs" />
|
||||
<Compile Include="Images\ImageRequest.cs" />
|
||||
<Compile Include="Images\ImageService.cs" />
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Fields to return within the items, in addition to basic information
|
||||
/// </summary>
|
||||
/// <value>The fields.</value>
|
||||
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: AudioInfo, Chapters, DateCreated, DisplayMediaType, DisplayPreferences, Genres, ItemCounts, IndexOptions, MediaStreams, Overview, OverviewHtml, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Publishers, SeriesInfo, SortName, Studios, Taglines, TrailerUrls, UserData", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
||||
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: AudioInfo, Chapters, DateCreated, DisplayMediaType, DisplayPreferences, Genres, ItemCounts, IndexOptions, MediaStreams, Overview, OverviewHtml, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, SeriesInfo, SortName, Studios, Taglines, TrailerUrls, UserData", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
||||
public string Fields { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
using System.Threading;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Connectivity;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using ServiceStack.ServiceHost;
|
||||
using ServiceStack.Text.Controller;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.UserLibrary
|
||||
|
@ -20,7 +16,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class GetItem
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}", "GET")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Gets an item from a user's library")]
|
||||
[Api(Description = "Gets an item from a user's library")]
|
||||
public class GetItem : IReturn<BaseItemDto>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -42,7 +38,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class GetItem
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/Root", "GET")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Gets the root folder from a user's library")]
|
||||
[Api(Description = "Gets the root folder from a user's library")]
|
||||
public class GetRootFolder : IReturn<BaseItemDto>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -57,7 +53,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class GetIntros
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}/Intros", "GET")]
|
||||
[ServiceStack.ServiceHost.Api(("Gets intros to play before the main media item plays"))]
|
||||
[Api(("Gets intros to play before the main media item plays"))]
|
||||
public class GetIntros : IReturn<List<string>>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -75,21 +71,6 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class UpdateDisplayPreferences
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}/DisplayPreferences", "POST")]
|
||||
[Api(("Updates a user's display preferences for an item"))]
|
||||
public class UpdateDisplayPreferences : DisplayPreferences, IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class MarkFavoriteItem
|
||||
/// </summary>
|
||||
|
@ -138,7 +119,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class ClearUserItemRating
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}/Rating", "DELETE")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Deletes a user's saved personal rating for an item")]
|
||||
[Api(Description = "Deletes a user's saved personal rating for an item")]
|
||||
public class DeleteUserItemRating : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -160,7 +141,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class UpdateUserItemRating
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}/Rating", "POST")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Updates a user's rating for an item")]
|
||||
[Api(Description = "Updates a user's rating for an item")]
|
||||
public class UpdateUserItemRating : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -189,7 +170,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class MarkPlayedItem
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/PlayedItems/{Id}", "POST")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Marks an item as played")]
|
||||
[Api(Description = "Marks an item as played")]
|
||||
public class MarkPlayedItem : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -211,7 +192,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class MarkUnplayedItem
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/PlayedItems/{Id}", "DELETE")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Marks an item as unplayed")]
|
||||
[Api(Description = "Marks an item as unplayed")]
|
||||
public class MarkUnplayedItem : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -230,7 +211,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
}
|
||||
|
||||
[Route("/Users/{UserId}/PlayingItems/{Id}", "POST")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Reports that a user has begun playing an item")]
|
||||
[Api(Description = "Reports that a user has begun playing an item")]
|
||||
public class OnPlaybackStart : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -249,7 +230,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
}
|
||||
|
||||
[Route("/Users/{UserId}/PlayingItems/{Id}/Progress", "POST")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Reports a user's playback progress")]
|
||||
[Api(Description = "Reports a user's playback progress")]
|
||||
public class OnPlaybackProgress : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -275,7 +256,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
}
|
||||
|
||||
[Route("/Users/{UserId}/PlayingItems/{Id}", "DELETE")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Reports that a user has stopped playing an item")]
|
||||
[Api(Description = "Reports that a user has stopped playing an item")]
|
||||
public class OnPlaybackStopped : IReturnVoid
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -304,7 +285,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class GetLocalTrailers
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}/LocalTrailers", "GET")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Gets local trailers for an item")]
|
||||
[Api(Description = "Gets local trailers for an item")]
|
||||
public class GetLocalTrailers : IReturn<List<BaseItemDto>>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -326,7 +307,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Class GetSpecialFeatures
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Items/{Id}/SpecialFeatures", "GET")]
|
||||
[ServiceStack.ServiceHost.Api(Description = "Gets special features for a movie")]
|
||||
[Api(Description = "Gets special features for a movie")]
|
||||
public class GetSpecialFeatures : IReturn<List<BaseItemDto>>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -356,18 +337,16 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
private readonly IUserManager _userManager;
|
||||
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserLibraryService" /> class.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
||||
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IJsonSerializer jsonSerializer)
|
||||
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager)
|
||||
: base()
|
||||
{
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -467,31 +446,6 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(UpdateDisplayPreferences request)
|
||||
{
|
||||
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
|
||||
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
|
||||
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
|
||||
var userId = new Guid(pathInfo.GetArgumentValue<string>(1));
|
||||
var itemId = pathInfo.GetArgumentValue<string>(3);
|
||||
|
||||
var user = _userManager.GetUserById(userId);
|
||||
|
||||
var item = string.IsNullOrEmpty(itemId) ? user.RootFolder : DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
|
||||
var folder = (Folder)item;
|
||||
|
||||
// Serialize to json and then back so that the core doesn't see the request dto type
|
||||
var displayPreferences = _jsonSerializer.DeserializeFromString<DisplayPreferences>(_jsonSerializer.SerializeToString(request));
|
||||
|
||||
var task = _userManager.SaveDisplayPreferences(user.Id, folder.DisplayPreferencesId, displayPreferences, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
|
|
|
@ -172,11 +172,9 @@ namespace MediaBrowser.Controller.Library
|
|||
dto.UserData = GetUserItemDataDto(userData);
|
||||
}
|
||||
|
||||
if (item.IsFolder && fields.Contains(ItemFields.DisplayPreferences))
|
||||
if (item.IsFolder && fields.Contains(ItemFields.DisplayPreferencesId))
|
||||
{
|
||||
var displayPreferencesId = ((Folder) item).DisplayPreferencesId;
|
||||
|
||||
dto.DisplayPreferences = await _userManager.GetDisplayPreferences(user.Id, displayPreferencesId).ConfigureAwait(false);
|
||||
dto.DisplayPreferencesId = ((Folder)item).DisplayPreferencesId.ToString();
|
||||
}
|
||||
|
||||
if (item.IsFolder)
|
||||
|
|
|
@ -207,7 +207,6 @@ namespace MediaBrowser.Controller.Library
|
|||
/// <param name="displayPreferences">The display preferences.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences,
|
||||
CancellationToken cancellationToken);
|
||||
Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -267,11 +267,11 @@ namespace MediaBrowser.Model.Dto
|
|||
public int? SpecialFeatureCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display preferences.
|
||||
/// Gets or sets the display preferences id.
|
||||
/// </summary>
|
||||
/// <value>The display preferences.</value>
|
||||
/// <value>The display preferences id.</value>
|
||||
[ProtoMember(49)]
|
||||
public DisplayPreferences DisplayPreferences { get; set; }
|
||||
public string DisplayPreferencesId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status.
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace MediaBrowser.Model.Querying
|
|||
/// <summary>
|
||||
/// Item display preferences
|
||||
/// </summary>
|
||||
DisplayPreferences,
|
||||
DisplayPreferencesId,
|
||||
|
||||
/// <summary>
|
||||
/// Genres
|
||||
|
|
Loading…
Reference in New Issue
Block a user