jellyfin-server/Jellyfin.Api/Controllers/DisplayPreferencesController.cs

77 lines
3.4 KiB
C#
Raw Normal View History

using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
2020-06-22 13:44:11 +00:00
using Jellyfin.Api.Constants;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
2020-04-23 16:07:21 +00:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
2020-04-19 18:06:18 +00:00
using Microsoft.AspNetCore.Mvc;
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
{
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.
/// </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>
[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-06-02 02:54:02 +00:00
return _displayPreferencesRepository.GetDisplayPreferences(displayPreferencesId, userId, client);
}
/// <summary>
2020-04-19 18:30:10 +00:00
/// 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="204">Display preferences updated.</response>
/// <returns>An <see cref="NoContentResult"/> on success.</returns>
[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,
[FromBody, BindRequired] DisplayPreferences displayPreferences)
{
2020-04-21 13:55:57 +00:00
_displayPreferencesRepository.SaveDisplayPreferences(
displayPreferences,
userId,
client,
CancellationToken.None);
return NoContent();
}
2020-04-19 18:06:18 +00:00
}
}