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