2020-04-19 18:56:16 +00:00
#nullable enable
2020-04-19 18:26:38 +00:00
using System.ComponentModel.DataAnnotations ;
using System.Threading ;
using MediaBrowser.Controller.Persistence ;
using MediaBrowser.Model.Entities ;
2020-04-23 16:07:21 +00:00
using Microsoft.AspNetCore.Authorization ;
2020-04-19 18:26:38 +00:00
using Microsoft.AspNetCore.Http ;
2020-04-19 18:06:18 +00:00
using Microsoft.AspNetCore.Mvc ;
2020-04-19 18:26:38 +00:00
using Microsoft.AspNetCore.Mvc.ModelBinding ;
2020-04-19 18:06:18 +00:00
namespace Jellyfin.Api.Controllers
{
/// <summary>
/// Display Preferences Controller.
/// </summary>
2020-04-23 16:07:21 +00:00
[Authorize]
2020-04-19 18:06:18 +00:00
public class DisplayPreferencesController : BaseJellyfinApiController
{
2020-04-19 18:26:38 +00:00
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>
2020-04-19 18:30:10 +00:00
/// Get Display Preferences.
2020-04-19 18:26:38 +00:00
/// </summary>
/// <param name="displayPreferencesId">Display preferences id.</param>
/// <param name="userId">User id.</param>
/// <param name="client">Client.</param>
2020-05-02 23:06:29 +00:00
/// <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>
2020-04-19 18:30:10 +00:00
[HttpGet("{DisplayPreferencesId}")]
2020-04-21 20:01:47 +00:00
[ProducesResponseType(StatusCodes.Status200OK)]
2020-04-19 18:26:38 +00:00
[ProducesResponseType(StatusCodes.Status404NotFound)]
2020-04-21 20:01:47 +00:00
public ActionResult < DisplayPreferences > GetDisplayPreferences (
2020-04-19 18:26:38 +00:00
[FromRoute] string displayPreferencesId ,
[FromQuery] [ Required ] string userId ,
2020-04-19 18:30:10 +00:00
[FromQuery] [ Required ] string client )
2020-04-19 18:26:38 +00:00
{
2020-06-02 02:54:02 +00:00
return _displayPreferencesRepository . GetDisplayPreferences ( displayPreferencesId , userId , client ) ;
2020-04-19 18:26:38 +00:00
}
/// <summary>
2020-04-19 18:30:10 +00:00
/// Update Display Preferences.
2020-04-19 18:26:38 +00:00
/// </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>
2020-05-02 23:06:29 +00:00
/// <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>
2020-04-19 18:26:38 +00:00
[HttpPost("{DisplayPreferencesId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ModelStateDictionary), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
2020-04-21 20:01:47 +00:00
public ActionResult UpdateDisplayPreferences (
2020-04-19 18:26:38 +00:00
[FromRoute] string displayPreferencesId ,
[FromQuery, BindRequired] string userId ,
[FromQuery, BindRequired] string client ,
[FromBody, BindRequired] DisplayPreferences displayPreferences )
{
2020-04-21 13:55:57 +00:00
if ( displayPreferencesId = = null )
2020-04-19 18:26:38 +00:00
{
2020-05-19 15:01:00 +00:00
// TODO - refactor so parameter doesn't exist or is actually used.
2020-04-19 18:26:38 +00:00
}
2020-04-21 13:55:57 +00:00
_displayPreferencesRepository . SaveDisplayPreferences (
displayPreferences ,
userId ,
client ,
CancellationToken . None ) ;
return Ok ( ) ;
2020-04-19 18:26:38 +00:00
}
2020-04-19 18:06:18 +00:00
}
}