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