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 { /// /// Display Preferences Controller. /// [Authorize] public class DisplayPreferencesController : BaseJellyfinApiController { private readonly IDisplayPreferencesRepository _displayPreferencesRepository; /// /// Initializes a new instance of the class. /// /// Instance of interface. public DisplayPreferencesController(IDisplayPreferencesRepository displayPreferencesRepository) { _displayPreferencesRepository = displayPreferencesRepository; } /// /// Get Display Preferences. /// /// Display preferences id. /// User id. /// Client. /// Display preferences retrieved. /// An containing the display preferences on success, or a if the display preferences could not be found. [HttpGet("{DisplayPreferencesId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult GetDisplayPreferences( [FromRoute] string displayPreferencesId, [FromQuery] [Required] string userId, [FromQuery] [Required] string client) { return _displayPreferencesRepository.GetDisplayPreferences(displayPreferencesId, userId, client); } /// /// Update Display Preferences. /// /// Display preferences id. /// User Id. /// Client. /// New Display Preferences object. /// Display preferences updated. /// An on success, or a if the display preferences could not be found. [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(); } } }