mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-16 05:53:03 +03:00
Move userId in API from route to optional query parameter (#11074)
* Move userId in API from route to optional query parameter * Standardize UserViewsController * Move userId to query in ImageController * Move userId to query in ItemsController * Move userId to query in PlaystateController * Move userId to query in SuggestionsController * Move userId from route to query in UserLibraryController * Clean up routes * Move userId to query in UserController * fix bad merge --------- Co-authored-by: Niels van Velzen <git@ndat.nl>
This commit is contained in:
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Jellyfin.Api.Extensions;
|
||||
using Jellyfin.Api.Helpers;
|
||||
using Jellyfin.Api.ModelBinders;
|
||||
using Jellyfin.Api.Models.UserViewDtos;
|
||||
using Jellyfin.Data.Enums;
|
||||
@@ -59,19 +60,17 @@ public class UserViewsController : BaseJellyfinApiController
|
||||
/// <param name="includeHidden">Whether or not to include hidden content.</param>
|
||||
/// <response code="200">User views returned.</response>
|
||||
/// <returns>An <see cref="OkResult"/> containing the user views.</returns>
|
||||
[HttpGet("Users/{userId}/Views")]
|
||||
[HttpGet("UserViews")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public QueryResult<BaseItemDto> GetUserViews(
|
||||
[FromRoute, Required] Guid userId,
|
||||
[FromQuery] Guid? userId,
|
||||
[FromQuery] bool? includeExternalContent,
|
||||
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] CollectionType?[] presetViews,
|
||||
[FromQuery] bool includeHidden = false)
|
||||
{
|
||||
var query = new UserViewQuery
|
||||
{
|
||||
UserId = userId,
|
||||
IncludeHidden = includeHidden
|
||||
};
|
||||
userId = RequestHelpers.GetUserId(User, userId);
|
||||
|
||||
var query = new UserViewQuery { UserId = userId.Value, IncludeHidden = includeHidden };
|
||||
|
||||
if (includeExternalContent.HasValue)
|
||||
{
|
||||
@@ -92,7 +91,7 @@ public class UserViewsController : BaseJellyfinApiController
|
||||
fields.Add(ItemFields.DisplayPreferencesId);
|
||||
dtoOptions.Fields = fields.ToArray();
|
||||
|
||||
var user = _userManager.GetUserById(userId);
|
||||
var user = _userManager.GetUserById(userId.Value);
|
||||
|
||||
var dtos = folders.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user))
|
||||
.ToArray();
|
||||
@@ -100,6 +99,26 @@ public class UserViewsController : BaseJellyfinApiController
|
||||
return new QueryResult<BaseItemDto>(dtos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user views.
|
||||
/// </summary>
|
||||
/// <param name="userId">User id.</param>
|
||||
/// <param name="includeExternalContent">Whether or not to include external views such as channels or live tv.</param>
|
||||
/// <param name="presetViews">Preset views.</param>
|
||||
/// <param name="includeHidden">Whether or not to include hidden content.</param>
|
||||
/// <response code="200">User views returned.</response>
|
||||
/// <returns>An <see cref="OkResult"/> containing the user views.</returns>
|
||||
[HttpGet("Users/{userId}/Views")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[Obsolete("Kept for backwards compatibility")]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public QueryResult<BaseItemDto> GetUserViewsLegacy(
|
||||
[FromRoute, Required] Guid userId,
|
||||
[FromQuery] bool? includeExternalContent,
|
||||
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] CollectionType?[] presetViews,
|
||||
[FromQuery] bool includeHidden = false)
|
||||
=> GetUserViews(userId, includeExternalContent, presetViews, includeHidden);
|
||||
|
||||
/// <summary>
|
||||
/// Get user view grouping options.
|
||||
/// </summary>
|
||||
@@ -110,12 +129,13 @@ public class UserViewsController : BaseJellyfinApiController
|
||||
/// An <see cref="OkResult"/> containing the user view grouping options
|
||||
/// or a <see cref="NotFoundResult"/> if user not found.
|
||||
/// </returns>
|
||||
[HttpGet("Users/{userId}/GroupingOptions")]
|
||||
[HttpGet("UserViews/GroupingOptions")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptions([FromRoute, Required] Guid userId)
|
||||
public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptions([FromQuery] Guid? userId)
|
||||
{
|
||||
var user = _userManager.GetUserById(userId);
|
||||
userId = RequestHelpers.GetUserId(User, userId);
|
||||
var user = _userManager.GetUserById(userId.Value);
|
||||
if (user is null)
|
||||
{
|
||||
return NotFound();
|
||||
@@ -133,4 +153,23 @@ public class UserViewsController : BaseJellyfinApiController
|
||||
.OrderBy(i => i.Name)
|
||||
.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user view grouping options.
|
||||
/// </summary>
|
||||
/// <param name="userId">User id.</param>
|
||||
/// <response code="200">User view grouping options returned.</response>
|
||||
/// <response code="404">User not found.</response>
|
||||
/// <returns>
|
||||
/// An <see cref="OkResult"/> containing the user view grouping options
|
||||
/// or a <see cref="NotFoundResult"/> if user not found.
|
||||
/// </returns>
|
||||
[HttpGet("Users/{userId}/GroupingOptions")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Obsolete("Kept for backwards compatibility")]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptionsLegacy(
|
||||
[FromRoute, Required] Guid userId)
|
||||
=> GetGroupingOptions(userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user