jellyfin/MediaBrowser.Api/DisplayPreferencesService.cs

95 lines
3.9 KiB
C#
Raw Normal View History

using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Serialization;
using System.Threading;
using System.Threading.Tasks;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Model.Services;
namespace MediaBrowser.Api
{
/// <summary>
/// Class UpdateDisplayPreferences
/// </summary>
2014-03-28 12:58:18 -07:00
[Route("/DisplayPreferences/{DisplayPreferencesId}", "POST", Summary = "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 = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-09-05 22:13:43 -07:00
public string DisplayPreferencesId { get; set; }
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
2015-05-29 16:51:33 -07:00
public string UserId { get; set; }
}
2014-03-28 12:58:18 -07:00
[Route("/DisplayPreferences/{Id}", "GET", Summary = "Gets a user's display preferences for an item")]
public class GetDisplayPreferences : IReturn<DisplayPreferences>
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-04-05 12:34:33 -07:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-09-05 22:13:43 -07:00
public string Id { get; set; }
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
2015-05-29 16:51:33 -07:00
public string UserId { get; set; }
[ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Client { get; set; }
}
/// <summary>
/// Class DisplayPreferencesService
/// </summary>
[Authenticated]
public class DisplayPreferencesService : BaseApiService
{
/// <summary>
2013-04-05 12:34:33 -07:00
/// The _display preferences manager
/// </summary>
2013-06-18 12:16:27 -07:00
private readonly IDisplayPreferencesRepository _displayPreferencesManager;
/// <summary>
/// The _json serializer
/// </summary>
private readonly IJsonSerializer _jsonSerializer;
/// <summary>
2013-04-05 12:34:33 -07:00
/// Initializes a new instance of the <see cref="DisplayPreferencesService" /> class.
/// </summary>
/// <param name="jsonSerializer">The json serializer.</param>
2013-04-05 12:34:33 -07:00
/// <param name="displayPreferencesManager">The display preferences manager.</param>
2013-06-18 12:16:27 -07:00
public DisplayPreferencesService(IJsonSerializer jsonSerializer, IDisplayPreferencesRepository displayPreferencesManager)
{
_jsonSerializer = jsonSerializer;
2013-04-05 12:34:33 -07:00
_displayPreferencesManager = displayPreferencesManager;
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
public object Get(GetDisplayPreferences request)
{
2014-05-08 13:09:53 -07:00
var result = _displayPreferencesManager.GetDisplayPreferences(request.Id, request.UserId, request.Client);
2013-09-05 22:13:43 -07:00
2018-09-12 10:26:21 -07:00
return ToOptimizedResult(result);
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Post(UpdateDisplayPreferences request)
{
// 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));
_displayPreferencesManager.SaveDisplayPreferences(displayPreferences, request.UserId, request.Client, CancellationToken.None);
}
}
}