From c083b29e292c72b65929ea05639e3b5a8a401037 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 1 Dec 2020 11:07:41 -0700 Subject: Use Guid as API parameter type where possible --- Jellyfin.Api/Controllers/FilterController.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'Jellyfin.Api/Controllers/FilterController.cs') diff --git a/Jellyfin.Api/Controllers/FilterController.cs b/Jellyfin.Api/Controllers/FilterController.cs index 31cb9e273..7b3111cff 100644 --- a/Jellyfin.Api/Controllers/FilterController.cs +++ b/Jellyfin.Api/Controllers/FilterController.cs @@ -50,13 +50,13 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] public ActionResult GetQueryFiltersLegacy( [FromQuery] Guid? userId, - [FromQuery] string? parentId, + [FromQuery] Guid? parentId, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] includeItemTypes, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes) { - var parentItem = string.IsNullOrEmpty(parentId) - ? null - : _libraryManager.GetItemById(parentId); + var parentItem = parentId.HasValue + ? _libraryManager.GetItemById(parentId.Value) + : null; var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) @@ -71,11 +71,11 @@ namespace Jellyfin.Api.Controllers parentItem = null; } - var item = string.IsNullOrEmpty(parentId) - ? user == null + var item = parentId.HasValue + ? parentItem + : user == null ? _libraryManager.RootFolder - : _libraryManager.GetUserRootFolder() - : parentItem; + : _libraryManager.GetUserRootFolder(); var query = new InternalItemsQuery { @@ -140,7 +140,7 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] public ActionResult GetQueryFilters( [FromQuery] Guid? userId, - [FromQuery] string? parentId, + [FromQuery] Guid? parentId, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] includeItemTypes, [FromQuery] bool? isAiring, [FromQuery] bool? isMovie, @@ -150,9 +150,9 @@ namespace Jellyfin.Api.Controllers [FromQuery] bool? isSeries, [FromQuery] bool? recursive) { - var parentItem = string.IsNullOrEmpty(parentId) - ? null - : _libraryManager.GetItemById(parentId); + var parentItem = parentId.HasValue + ? _libraryManager.GetItemById(parentId.Value) + : null; var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) -- cgit v1.2.3 From f48e47be5fcd5d51a4001caa05f429cf92b4a8ed Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 1 Dec 2020 12:10:11 -0700 Subject: Split nested conditional --- Jellyfin.Api/Controllers/FilterController.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Jellyfin.Api/Controllers/FilterController.cs') diff --git a/Jellyfin.Api/Controllers/FilterController.cs b/Jellyfin.Api/Controllers/FilterController.cs index 7b3111cff..521960ae6 100644 --- a/Jellyfin.Api/Controllers/FilterController.cs +++ b/Jellyfin.Api/Controllers/FilterController.cs @@ -71,11 +71,19 @@ namespace Jellyfin.Api.Controllers parentItem = null; } - var item = parentId.HasValue - ? parentItem - : user == null - ? _libraryManager.RootFolder - : _libraryManager.GetUserRootFolder(); + BaseItem? item; + if (parentId.HasValue) + { + item = parentItem; + } + else if (user == null) + { + item = _libraryManager.RootFolder; + } + else + { + item = _libraryManager.GetUserRootFolder(); + } var query = new InternalItemsQuery { -- cgit v1.2.3 From 09b1e571f4e4dad19495e8873a5bc712a3bf9b7c Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 2 Dec 2020 07:11:42 -0700 Subject: Apply suggestions from review --- Jellyfin.Api/Controllers/FilterController.cs | 40 +++++++++------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'Jellyfin.Api/Controllers/FilterController.cs') diff --git a/Jellyfin.Api/Controllers/FilterController.cs b/Jellyfin.Api/Controllers/FilterController.cs index 521960ae6..1c0f1c1df 100644 --- a/Jellyfin.Api/Controllers/FilterController.cs +++ b/Jellyfin.Api/Controllers/FilterController.cs @@ -54,35 +54,18 @@ namespace Jellyfin.Api.Controllers [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] includeItemTypes, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes) { - var parentItem = parentId.HasValue - ? _libraryManager.GetItemById(parentId.Value) - : null; - var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; - if (includeItemTypes.Length == 1 - && (string.Equals(includeItemTypes[0], nameof(BoxSet), StringComparison.OrdinalIgnoreCase) - || string.Equals(includeItemTypes[0], nameof(Playlist), StringComparison.OrdinalIgnoreCase) - || string.Equals(includeItemTypes[0], nameof(Trailer), StringComparison.OrdinalIgnoreCase) - || string.Equals(includeItemTypes[0], "Program", StringComparison.OrdinalIgnoreCase))) - { - parentItem = null; - } - - BaseItem? item; - if (parentId.HasValue) - { - item = parentItem; - } - else if (user == null) - { - item = _libraryManager.RootFolder; - } - else + BaseItem? item = null; + if (includeItemTypes.Length != 1 + || !(string.Equals(includeItemTypes[0], nameof(BoxSet), StringComparison.OrdinalIgnoreCase) + || string.Equals(includeItemTypes[0], nameof(Playlist), StringComparison.OrdinalIgnoreCase) + || string.Equals(includeItemTypes[0], nameof(Trailer), StringComparison.OrdinalIgnoreCase) + || string.Equals(includeItemTypes[0], "Program", StringComparison.OrdinalIgnoreCase))) { - item = _libraryManager.GetUserRootFolder(); + item = _libraryManager.GetParentItem(parentId, user?.Id); } var query = new InternalItemsQuery @@ -158,14 +141,11 @@ namespace Jellyfin.Api.Controllers [FromQuery] bool? isSeries, [FromQuery] bool? recursive) { - var parentItem = parentId.HasValue - ? _libraryManager.GetItemById(parentId.Value) - : null; - var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; + BaseItem? parentItem = null; if (includeItemTypes.Length == 1 && (string.Equals(includeItemTypes[0], nameof(BoxSet), StringComparison.OrdinalIgnoreCase) || string.Equals(includeItemTypes[0], nameof(Playlist), StringComparison.OrdinalIgnoreCase) @@ -174,6 +154,10 @@ namespace Jellyfin.Api.Controllers { parentItem = null; } + else if (parentId.HasValue) + { + parentItem = _libraryManager.GetItemById(parentId.Value); + } var filters = new QueryFilters(); var genreQuery = new InternalItemsQuery(user) -- cgit v1.2.3