2020-04-19 18:26:38 +00:00
using System.ComponentModel.DataAnnotations ;
2020-06-21 00:02:07 +00:00
using System.Diagnostics.CodeAnalysis ;
2020-04-19 18:26:38 +00:00
using System.Threading ;
2020-06-22 13:44:11 +00:00
using Jellyfin.Api.Constants ;
2020-04-19 18:26:38 +00:00
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-06-22 13:44:11 +00:00
[Authorize(Policy = Policies.DefaultAuthorization)]
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-06-21 00:02:07 +00:00
[HttpGet("{displayPreferencesId}")]
2020-04-21 20:01:47 +00:00
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult < DisplayPreferences > GetDisplayPreferences (
2020-06-27 16:50:44 +00:00
[FromRoute] string? displayPreferencesId ,
[FromQuery] [ Required ] string? userId ,
[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-06-21 00:02:07 +00:00
/// <response code="204">Display preferences updated.</response>
2020-06-21 15:33:34 +00:00
/// <returns>An <see cref="NoContentResult"/> on success.</returns>
2020-06-21 00:02:07 +00:00
[HttpPost("{displayPreferencesId}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "displayPreferencesId", Justification = "Imported from ServiceStack")]
2020-04-21 20:01:47 +00:00
public ActionResult UpdateDisplayPreferences (
2020-06-27 16:50:44 +00:00
[FromRoute] string? displayPreferencesId ,
[FromQuery, BindRequired] string? userId ,
[FromQuery, BindRequired] string? client ,
2020-04-19 18:26:38 +00:00
[FromBody, BindRequired] DisplayPreferences displayPreferences )
{
2020-04-21 13:55:57 +00:00
_displayPreferencesRepository . SaveDisplayPreferences (
displayPreferences ,
userId ,
client ,
CancellationToken . None ) ;
2020-06-21 00:02:07 +00:00
return NoContent ( ) ;
2020-04-19 18:26:38 +00:00
}
2020-04-19 18:06:18 +00:00
}
}