2013-09-06 01:13:43 -04:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2013-04-05 13:10:55 -04:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-12-07 10:52:38 -05:00
|
|
|
|
using ServiceStack;
|
2013-04-05 13:10:55 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdateDisplayPreferences
|
|
|
|
|
/// </summary>
|
2013-04-05 15:02:48 -04:00
|
|
|
|
[Route("/DisplayPreferences/{DisplayPreferencesId}", "POST")]
|
2013-04-05 13:10:55 -04:00
|
|
|
|
[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>
|
2013-04-05 15:02:48 -04:00
|
|
|
|
[ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-09-06 01:13:43 -04:00
|
|
|
|
public string DisplayPreferencesId { get; set; }
|
2013-07-26 21:15:55 -04:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public string Client { get; set; }
|
2013-04-05 13:10:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-05 15:02:48 -04:00
|
|
|
|
[Route("/DisplayPreferences/{Id}", "GET")]
|
2013-04-05 13:10:55 -04:00
|
|
|
|
[Api(("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 15:34:33 -04:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-09-06 01:13:43 -04:00
|
|
|
|
public string Id { get; set; }
|
2013-07-26 21:15:55 -04:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string Client { get; set; }
|
2013-04-05 13:10:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class DisplayPreferencesService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DisplayPreferencesService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2013-04-05 15:34:33 -04:00
|
|
|
|
/// The _display preferences manager
|
2013-04-05 13:10:55 -04:00
|
|
|
|
/// </summary>
|
2013-06-18 15:16:27 -04:00
|
|
|
|
private readonly IDisplayPreferencesRepository _displayPreferencesManager;
|
2013-04-05 13:10:55 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _json serializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-04-05 15:34:33 -04:00
|
|
|
|
/// Initializes a new instance of the <see cref="DisplayPreferencesService" /> class.
|
2013-04-05 13:10:55 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="jsonSerializer">The json serializer.</param>
|
2013-04-05 15:34:33 -04:00
|
|
|
|
/// <param name="displayPreferencesManager">The display preferences manager.</param>
|
2013-06-18 15:16:27 -04:00
|
|
|
|
public DisplayPreferencesService(IJsonSerializer jsonSerializer, IDisplayPreferencesRepository displayPreferencesManager)
|
2013-04-05 13:10:55 -04:00
|
|
|
|
{
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
2013-04-05 15:34:33 -04:00
|
|
|
|
_displayPreferencesManager = displayPreferencesManager;
|
2013-04-05 13:10:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public object Get(GetDisplayPreferences request)
|
|
|
|
|
{
|
2013-09-06 01:13:43 -04:00
|
|
|
|
Guid displayPreferencesId;
|
|
|
|
|
|
|
|
|
|
if (!Guid.TryParse(request.Id, out displayPreferencesId))
|
|
|
|
|
{
|
|
|
|
|
displayPreferencesId = request.Id.GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = _displayPreferencesManager.GetDisplayPreferences(displayPreferencesId, request.UserId, request.Client);
|
2013-04-05 13:10:55 -04:00
|
|
|
|
|
2013-06-18 15:16:27 -04:00
|
|
|
|
return ToOptimizedResult(result);
|
2013-04-05 13:10:55 -04: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));
|
|
|
|
|
|
2013-07-26 21:15:55 -04:00
|
|
|
|
var task = _displayPreferencesManager.SaveDisplayPreferences(displayPreferences, request.UserId, request.Client, CancellationToken.None);
|
2013-04-05 13:10:55 -04:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|