mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 22:07:13 -04:00
Merge pull request #2926 from crobibero/api-display-preferences
DisplayPreferences to Jellyfin.Api
This commit is contained in:
commit
c3915cdb78
81
Jellyfin.Api/Controllers/DisplayPreferencesController.cs
Normal file
81
Jellyfin.Api/Controllers/DisplayPreferencesController.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Threading;
|
||||||
|
using MediaBrowser.Controller.Persistence;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Display Preferences Controller.
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public class DisplayPreferencesController : BaseJellyfinApiController
|
||||||
|
{
|
||||||
|
private readonly IDisplayPreferencesRepository _displayPreferencesRepository;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="DisplayPreferencesController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="displayPreferencesRepository">Instance of <see cref="IDisplayPreferencesRepository"/> interface.</param>
|
||||||
|
public DisplayPreferencesController(IDisplayPreferencesRepository displayPreferencesRepository)
|
||||||
|
{
|
||||||
|
_displayPreferencesRepository = displayPreferencesRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Display Preferences.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="displayPreferencesId">Display preferences id.</param>
|
||||||
|
/// <param name="userId">User id.</param>
|
||||||
|
/// <param name="client">Client.</param>
|
||||||
|
/// <response code="200">Display preferences retrieved.</response>
|
||||||
|
/// <returns>An <see cref="OkResult"/> containing the display preferences on success, or a <see cref="NotFoundResult"/> if the display preferences could not be found.</returns>
|
||||||
|
[HttpGet("{DisplayPreferencesId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult<DisplayPreferences> GetDisplayPreferences(
|
||||||
|
[FromRoute] string displayPreferencesId,
|
||||||
|
[FromQuery] [Required] string userId,
|
||||||
|
[FromQuery] [Required] string client)
|
||||||
|
{
|
||||||
|
return _displayPreferencesRepository.GetDisplayPreferences(displayPreferencesId, userId, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Display Preferences.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="displayPreferencesId">Display preferences id.</param>
|
||||||
|
/// <param name="userId">User Id.</param>
|
||||||
|
/// <param name="client">Client.</param>
|
||||||
|
/// <param name="displayPreferences">New Display Preferences object.</param>
|
||||||
|
/// <response code="200">Display preferences updated.</response>
|
||||||
|
/// <returns>An <see cref="OkResult"/> on success, or a <see cref="NotFoundResult"/> if the display preferences could not be found.</returns>
|
||||||
|
[HttpPost("{DisplayPreferencesId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(ModelStateDictionary), StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult UpdateDisplayPreferences(
|
||||||
|
[FromRoute] string displayPreferencesId,
|
||||||
|
[FromQuery, BindRequired] string userId,
|
||||||
|
[FromQuery, BindRequired] string client,
|
||||||
|
[FromBody, BindRequired] DisplayPreferences displayPreferences)
|
||||||
|
{
|
||||||
|
if (displayPreferencesId == null)
|
||||||
|
{
|
||||||
|
// TODO - refactor so parameter doesn't exist or is actually used.
|
||||||
|
}
|
||||||
|
|
||||||
|
_displayPreferencesRepository.SaveDisplayPreferences(
|
||||||
|
displayPreferences,
|
||||||
|
userId,
|
||||||
|
client,
|
||||||
|
CancellationToken.None);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,101 +0,0 @@
|
|||||||
using System.Threading;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Controller.Persistence;
|
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
using MediaBrowser.Model.Serialization;
|
|
||||||
using MediaBrowser.Model.Services;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Class UpdateDisplayPreferences
|
|
||||||
/// </summary>
|
|
||||||
[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")]
|
|
||||||
public string DisplayPreferencesId { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
||||||
public string UserId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[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>
|
|
||||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
||||||
public string Id { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
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>
|
|
||||||
/// The _display preferences manager
|
|
||||||
/// </summary>
|
|
||||||
private readonly IDisplayPreferencesRepository _displayPreferencesManager;
|
|
||||||
/// <summary>
|
|
||||||
/// The _json serializer
|
|
||||||
/// </summary>
|
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="DisplayPreferencesService" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="jsonSerializer">The json serializer.</param>
|
|
||||||
/// <param name="displayPreferencesManager">The display preferences manager.</param>
|
|
||||||
public DisplayPreferencesService(
|
|
||||||
ILogger<DisplayPreferencesService> logger,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory,
|
|
||||||
IJsonSerializer jsonSerializer,
|
|
||||||
IDisplayPreferencesRepository displayPreferencesManager)
|
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
_jsonSerializer = jsonSerializer;
|
|
||||||
_displayPreferencesManager = displayPreferencesManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the specified request.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
public object Get(GetDisplayPreferences request)
|
|
||||||
{
|
|
||||||
var result = _displayPreferencesManager.GetDisplayPreferences(request.Id, request.UserId, request.Client);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user