diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index 4bcc75e60..eb18394fc 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -158,6 +158,8 @@ namespace NzbDrone.Host { { apikeyQuery, Array.Empty() } }); + + c.DescribeAllParametersInCamelCase(); }); services diff --git a/src/NzbDrone.Integration.Test/ApiTests/WantedTests/CutoffUnmetFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/WantedTests/CutoffUnmetFixture.cs index 1a75068e4..1b4a2b61d 100644 --- a/src/NzbDrone.Integration.Test/ApiTests/WantedTests/CutoffUnmetFixture.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/WantedTests/CutoffUnmetFixture.cs @@ -56,7 +56,7 @@ namespace NzbDrone.Integration.Test.ApiTests.WantedTests var series = EnsureSeries(266189, "The Blacklist", false); EnsureEpisodeFile(series, 1, 1, Quality.SDTV); - var result = WantedCutoffUnmet.GetPaged(0, 15, "airDateUtc", "desc", "monitored", "false"); + var result = WantedCutoffUnmet.GetPaged(0, 15, "airDateUtc", "desc", "monitored", false); result.Records.Should().NotBeEmpty(); } diff --git a/src/NzbDrone.Integration.Test/ApiTests/WantedTests/MissingFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/WantedTests/MissingFixture.cs index a91b954f7..bc6ef9dfa 100644 --- a/src/NzbDrone.Integration.Test/ApiTests/WantedTests/MissingFixture.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/WantedTests/MissingFixture.cs @@ -58,7 +58,7 @@ namespace NzbDrone.Integration.Test.ApiTests.WantedTests { EnsureSeries(266189, "The Blacklist", false); - var result = WantedMissing.GetPaged(0, 15, "airDateUtc", "desc", "monitored", "false"); + var result = WantedMissing.GetPaged(0, 15, "airDateUtc", "desc", "monitored", false); result.Records.Should().NotBeEmpty(); } diff --git a/src/NzbDrone.Integration.Test/Client/ClientBase.cs b/src/NzbDrone.Integration.Test/Client/ClientBase.cs index 8e2091f94..aa45059f6 100644 --- a/src/NzbDrone.Integration.Test/Client/ClientBase.cs +++ b/src/NzbDrone.Integration.Test/Client/ClientBase.cs @@ -102,7 +102,7 @@ namespace NzbDrone.Integration.Test.Client return Get>(request); } - public PagingResource GetPaged(int pageNumber, int pageSize, string sortKey, string sortDir, string filterKey = null, string filterValue = null) + public PagingResource GetPaged(int pageNumber, int pageSize, string sortKey, string sortDir, string filterKey = null, object filterValue = null) { var request = BuildRequest(); request.AddParameter("page", pageNumber); @@ -113,8 +113,7 @@ namespace NzbDrone.Integration.Test.Client if (filterKey != null && filterValue != null) { - request.AddParameter("filterKey", filterKey); - request.AddParameter("filterValue", filterValue); + request.AddParameter(filterKey, filterValue); } return Get>(request); diff --git a/src/Sonarr.Api.V3/Blocklist/BlocklistController.cs b/src/Sonarr.Api.V3/Blocklist/BlocklistController.cs index b5c9392b8..2091d3cfe 100644 --- a/src/Sonarr.Api.V3/Blocklist/BlocklistController.cs +++ b/src/Sonarr.Api.V3/Blocklist/BlocklistController.cs @@ -23,9 +23,9 @@ namespace Sonarr.Api.V3.Blocklist [HttpGet] [Produces("application/json")] - public PagingResource GetBlocklist() + public PagingResource GetBlocklist([FromQuery] PagingRequestResource paging) { - var pagingResource = Request.ReadPagingResourceFromRequest(); + var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec("date", SortDirection.Descending); return pagingSpec.ApplyToPage(_blocklistService.Paged, model => BlocklistResourceMapper.MapToResource(model, _formatCalculator)); diff --git a/src/Sonarr.Api.V3/History/HistoryController.cs b/src/Sonarr.Api.V3/History/HistoryController.cs index cb6075676..088ed9163 100644 --- a/src/Sonarr.Api.V3/History/HistoryController.cs +++ b/src/Sonarr.Api.V3/History/HistoryController.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; +using NzbDrone.Common.Extensions; using NzbDrone.Core.CustomFormats; using NzbDrone.Core.Datastore; using NzbDrone.Core.DecisionEngine.Specifications; @@ -61,30 +62,24 @@ namespace Sonarr.Api.V3.History [HttpGet] [Produces("application/json")] - public PagingResource GetHistory(bool includeSeries, bool includeEpisode) + public PagingResource GetHistory([FromQuery] PagingRequestResource paging, bool includeSeries, bool includeEpisode, int? eventType, int? episodeId, string downloadId) { - var pagingResource = Request.ReadPagingResourceFromRequest(); + var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec("date", SortDirection.Descending); - var eventTypeFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "eventType"); - var episodeIdFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "episodeId"); - var downloadIdFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "downloadId"); - - if (eventTypeFilter != null) + if (eventType.HasValue) { - var filterValue = (EpisodeHistoryEventType)Convert.ToInt32(eventTypeFilter.Value); + var filterValue = (EpisodeHistoryEventType)eventType.Value; pagingSpec.FilterExpressions.Add(v => v.EventType == filterValue); } - if (episodeIdFilter != null) + if (episodeId.HasValue) { - var episodeId = Convert.ToInt32(episodeIdFilter.Value); pagingSpec.FilterExpressions.Add(h => h.EpisodeId == episodeId); } - if (downloadIdFilter != null) + if (downloadId.IsNotNullOrWhiteSpace()) { - var downloadId = downloadIdFilter.Value; pagingSpec.FilterExpressions.Add(h => h.DownloadId == downloadId); } diff --git a/src/Sonarr.Api.V3/Logs/LogController.cs b/src/Sonarr.Api.V3/Logs/LogController.cs index 3350bcce3..e838bc7e6 100644 --- a/src/Sonarr.Api.V3/Logs/LogController.cs +++ b/src/Sonarr.Api.V3/Logs/LogController.cs @@ -1,5 +1,5 @@ -using System.Linq; using Microsoft.AspNetCore.Mvc; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Instrumentation; using Sonarr.Http; using Sonarr.Http.Extensions; @@ -18,9 +18,9 @@ namespace Sonarr.Api.V3.Logs [HttpGet] [Produces("application/json")] - public PagingResource GetLogs() + public PagingResource GetLogs([FromQuery] PagingRequestResource paging, string level) { - var pagingResource = Request.ReadPagingResourceFromRequest(); + var pagingResource = new PagingResource(paging); var pageSpec = pagingResource.MapToPagingSpec(); if (pageSpec.SortKey == "time") @@ -28,11 +28,9 @@ namespace Sonarr.Api.V3.Logs pageSpec.SortKey = "id"; } - var levelFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "level"); - - if (levelFilter != null) + if (level.IsNotNullOrWhiteSpace()) { - switch (levelFilter.Value) + switch (level) { case "fatal": pageSpec.FilterExpressions.Add(h => h.Level == "Fatal"); diff --git a/src/Sonarr.Api.V3/Queue/QueueController.cs b/src/Sonarr.Api.V3/Queue/QueueController.cs index 6259956c3..edb631ee4 100644 --- a/src/Sonarr.Api.V3/Queue/QueueController.cs +++ b/src/Sonarr.Api.V3/Queue/QueueController.cs @@ -135,9 +135,9 @@ namespace Sonarr.Api.V3.Queue [HttpGet] [Produces("application/json")] - public PagingResource GetQueue(bool includeUnknownSeriesItems = false, bool includeSeries = false, bool includeEpisode = false) + public PagingResource GetQueue([FromQuery] PagingRequestResource paging, bool includeUnknownSeriesItems = false, bool includeSeries = false, bool includeEpisode = false) { - var pagingResource = Request.ReadPagingResourceFromRequest(); + var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec("timeleft", SortDirection.Ascending); return pagingSpec.ApplyToPage((spec) => GetQueue(spec, includeUnknownSeriesItems), (q) => MapToResource(q, includeSeries, includeEpisode)); diff --git a/src/Sonarr.Api.V3/Wanted/CutoffController.cs b/src/Sonarr.Api.V3/Wanted/CutoffController.cs index b906399b0..479212ec7 100644 --- a/src/Sonarr.Api.V3/Wanted/CutoffController.cs +++ b/src/Sonarr.Api.V3/Wanted/CutoffController.cs @@ -1,4 +1,3 @@ -using System.Linq; using Microsoft.AspNetCore.Mvc; using NzbDrone.Core.CustomFormats; using NzbDrone.Core.Datastore; @@ -29,9 +28,9 @@ namespace Sonarr.Api.V3.Wanted [HttpGet] [Produces("application/json")] - public PagingResource GetCutoffUnmetEpisodes(bool includeSeries = false, bool includeEpisodeFile = false, bool includeImages = false) + public PagingResource GetCutoffUnmetEpisodes([FromQuery] PagingRequestResource paging, bool includeSeries = false, bool includeEpisodeFile = false, bool includeImages = false, bool monitored = true) { - var pagingResource = Request.ReadPagingResourceFromRequest(); + var pagingResource = new PagingResource(paging); var pagingSpec = new PagingSpec { Page = pagingResource.Page, @@ -40,16 +39,7 @@ namespace Sonarr.Api.V3.Wanted SortDirection = pagingResource.SortDirection }; - var filter = pagingResource.Filters.FirstOrDefault(f => f.Key == "monitored"); - - if (filter != null && filter.Value == "false") - { - pagingSpec.FilterExpressions.Add(v => v.Monitored == false || v.Series.Monitored == false); - } - else - { - pagingSpec.FilterExpressions.Add(v => v.Monitored == true && v.Series.Monitored == true); - } + pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored || v.Series.Monitored == monitored); var resource = pagingSpec.ApplyToPage(_episodeCutoffService.EpisodesWhereCutoffUnmet, v => MapToResource(v, includeSeries, includeEpisodeFile, includeImages)); diff --git a/src/Sonarr.Api.V3/Wanted/MissingController.cs b/src/Sonarr.Api.V3/Wanted/MissingController.cs index 6ed40dda7..43832c0d2 100644 --- a/src/Sonarr.Api.V3/Wanted/MissingController.cs +++ b/src/Sonarr.Api.V3/Wanted/MissingController.cs @@ -1,4 +1,3 @@ -using System.Linq; using Microsoft.AspNetCore.Mvc; using NzbDrone.Core.CustomFormats; using NzbDrone.Core.Datastore; @@ -25,9 +24,9 @@ namespace Sonarr.Api.V3.Wanted [HttpGet] [Produces("application/json")] - public PagingResource GetMissingEpisodes(bool includeSeries = false, bool includeImages = false) + public PagingResource GetMissingEpisodes([FromQuery] PagingRequestResource paging, bool includeSeries = false, bool includeImages = false, bool monitored = true) { - var pagingResource = Request.ReadPagingResourceFromRequest(); + var pagingResource = new PagingResource(paging); var pagingSpec = new PagingSpec { Page = pagingResource.Page, @@ -36,16 +35,7 @@ namespace Sonarr.Api.V3.Wanted SortDirection = pagingResource.SortDirection }; - var monitoredFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "monitored"); - - if (monitoredFilter != null && monitoredFilter.Value == "false") - { - pagingSpec.FilterExpressions.Add(v => v.Monitored == false || v.Series.Monitored == false); - } - else - { - pagingSpec.FilterExpressions.Add(v => v.Monitored == true && v.Series.Monitored == true); - } + pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored || v.Series.Monitored == monitored); var resource = pagingSpec.ApplyToPage(_episodeService.EpisodesWithoutFiles, v => MapToResource(v, includeSeries, false, includeImages)); diff --git a/src/Sonarr.Api.V3/openapi.json b/src/Sonarr.Api.V3/openapi.json index ef261ba3c..462f08b69 100644 --- a/src/Sonarr.Api.V3/openapi.json +++ b/src/Sonarr.Api.V3/openapi.json @@ -59,25 +59,25 @@ "schema": { "type": "object", "properties": { - "Username": { + "username": { "type": "string" }, - "Password": { + "password": { "type": "string" }, - "RememberMe": { + "rememberMe": { "type": "string" } } }, "encoding": { - "Username": { + "username": { "style": "form" }, - "Password": { + "password": { "style": "form" }, - "RememberMe": { + "rememberMe": { "style": "form" } } @@ -381,6 +381,40 @@ "tags": [ "Blocklist" ], + "parameters": [ + { + "name": "page", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 1 + } + }, + { + "name": "pageSize", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 10 + } + }, + { + "name": "sortKey", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "sortDirection", + "in": "query", + "schema": { + "$ref": "#/components/schemas/SortDirection" + } + } + ], "responses": { "200": { "description": "Success", @@ -1050,6 +1084,38 @@ "Cutoff" ], "parameters": [ + { + "name": "page", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 1 + } + }, + { + "name": "pageSize", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 10 + } + }, + { + "name": "sortKey", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "sortDirection", + "in": "query", + "schema": { + "$ref": "#/components/schemas/SortDirection" + } + }, { "name": "includeSeries", "in": "query", @@ -1073,6 +1139,14 @@ "type": "boolean", "default": false } + }, + { + "name": "monitored", + "in": "query", + "schema": { + "type": "boolean", + "default": true + } } ], "responses": { @@ -2220,6 +2294,38 @@ "History" ], "parameters": [ + { + "name": "page", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 1 + } + }, + { + "name": "pageSize", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 10 + } + }, + { + "name": "sortKey", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "sortDirection", + "in": "query", + "schema": { + "$ref": "#/components/schemas/SortDirection" + } + }, { "name": "includeSeries", "in": "query", @@ -2233,6 +2339,29 @@ "schema": { "type": "boolean" } + }, + { + "name": "eventType", + "in": "query", + "schema": { + "type": "integer", + "format": "int32" + } + }, + { + "name": "episodeId", + "in": "query", + "schema": { + "type": "integer", + "format": "int32" + } + }, + { + "name": "downloadId", + "in": "query", + "schema": { + "type": "string" + } } ], "responses": { @@ -3627,6 +3756,47 @@ "tags": [ "Log" ], + "parameters": [ + { + "name": "page", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 1 + } + }, + { + "name": "pageSize", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 10 + } + }, + { + "name": "sortKey", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "sortDirection", + "in": "query", + "schema": { + "$ref": "#/components/schemas/SortDirection" + } + }, + { + "name": "level", + "in": "query", + "schema": { + "type": "string" + } + } + ], "responses": { "200": { "description": "Success", @@ -4142,6 +4312,38 @@ "Missing" ], "parameters": [ + { + "name": "page", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 1 + } + }, + { + "name": "pageSize", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 10 + } + }, + { + "name": "sortKey", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "sortDirection", + "in": "query", + "schema": { + "$ref": "#/components/schemas/SortDirection" + } + }, { "name": "includeSeries", "in": "query", @@ -4157,6 +4359,14 @@ "type": "boolean", "default": false } + }, + { + "name": "monitored", + "in": "query", + "schema": { + "type": "boolean", + "default": true + } } ], "responses": { @@ -4325,21 +4535,21 @@ ], "parameters": [ { - "name": "RenameEpisodes", + "name": "renameEpisodes", "in": "query", "schema": { "type": "boolean" } }, { - "name": "ReplaceIllegalCharacters", + "name": "replaceIllegalCharacters", "in": "query", "schema": { "type": "boolean" } }, { - "name": "ColonReplacementFormat", + "name": "colonReplacementFormat", "in": "query", "schema": { "type": "integer", @@ -4347,7 +4557,7 @@ } }, { - "name": "MultiEpisodeStyle", + "name": "multiEpisodeStyle", "in": "query", "schema": { "type": "integer", @@ -4355,91 +4565,91 @@ } }, { - "name": "StandardEpisodeFormat", + "name": "standardEpisodeFormat", "in": "query", "schema": { "type": "string" } }, { - "name": "DailyEpisodeFormat", + "name": "dailyEpisodeFormat", "in": "query", "schema": { "type": "string" } }, { - "name": "AnimeEpisodeFormat", + "name": "animeEpisodeFormat", "in": "query", "schema": { "type": "string" } }, { - "name": "SeriesFolderFormat", + "name": "seriesFolderFormat", "in": "query", "schema": { "type": "string" } }, { - "name": "SeasonFolderFormat", + "name": "seasonFolderFormat", "in": "query", "schema": { "type": "string" } }, { - "name": "SpecialsFolderFormat", + "name": "specialsFolderFormat", "in": "query", "schema": { "type": "string" } }, { - "name": "IncludeSeriesTitle", + "name": "includeSeriesTitle", "in": "query", "schema": { "type": "boolean" } }, { - "name": "IncludeEpisodeTitle", + "name": "includeEpisodeTitle", "in": "query", "schema": { "type": "boolean" } }, { - "name": "IncludeQuality", + "name": "includeQuality", "in": "query", "schema": { "type": "boolean" } }, { - "name": "ReplaceSpaces", + "name": "replaceSpaces", "in": "query", "schema": { "type": "boolean" } }, { - "name": "Separator", + "name": "separator", "in": "query", "schema": { "type": "string" } }, { - "name": "NumberStyle", + "name": "numberStyle", "in": "query", "schema": { "type": "string" } }, { - "name": "Id", + "name": "id", "in": "query", "schema": { "type": "integer", @@ -4447,7 +4657,7 @@ } }, { - "name": "ResourceName", + "name": "resourceName", "in": "query", "schema": { "type": "string" @@ -5212,6 +5422,38 @@ "Queue" ], "parameters": [ + { + "name": "page", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 1 + } + }, + { + "name": "pageSize", + "in": "query", + "schema": { + "type": "integer", + "format": "int32", + "default": 10 + } + }, + { + "name": "sortKey", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "sortDirection", + "in": "query", + "schema": { + "$ref": "#/components/schemas/SortDirection" + } + }, { "name": "includeUnknownSeriesItems", "in": "query", @@ -7185,13 +7427,6 @@ "sortDirection": { "$ref": "#/components/schemas/SortDirection" }, - "filters": { - "type": "array", - "items": { - "$ref": "#/components/schemas/PagingResourceFilter" - }, - "nullable": true - }, "totalRecords": { "type": "integer", "format": "int32" @@ -7402,7 +7637,7 @@ "type": "array", "items": { "type": "object", - "additionalProperties": { } + "additionalProperties": {} }, "nullable": true } @@ -7951,13 +8186,6 @@ "sortDirection": { "$ref": "#/components/schemas/SortDirection" }, - "filters": { - "type": "array", - "items": { - "$ref": "#/components/schemas/PagingResourceFilter" - }, - "nullable": true - }, "totalRecords": { "type": "integer", "format": "int32" @@ -8200,13 +8428,6 @@ "sortDirection": { "$ref": "#/components/schemas/SortDirection" }, - "filters": { - "type": "array", - "items": { - "$ref": "#/components/schemas/PagingResourceFilter" - }, - "nullable": true - }, "totalRecords": { "type": "integer", "format": "int32" @@ -8891,13 +9112,6 @@ "sortDirection": { "$ref": "#/components/schemas/SortDirection" }, - "filters": { - "type": "array", - "items": { - "$ref": "#/components/schemas/PagingResourceFilter" - }, - "nullable": true - }, "totalRecords": { "type": "integer", "format": "int32" @@ -9549,20 +9763,6 @@ }, "additionalProperties": false }, - "PagingResourceFilter": { - "type": "object", - "properties": { - "key": { - "type": "string", - "nullable": true - }, - "value": { - "type": "string", - "nullable": true - } - }, - "additionalProperties": false - }, "ParseResource": { "type": "object", "properties": { @@ -10096,13 +10296,6 @@ "sortDirection": { "$ref": "#/components/schemas/SortDirection" }, - "filters": { - "type": "array", - "items": { - "$ref": "#/components/schemas/PagingResourceFilter" - }, - "nullable": true - }, "totalRecords": { "type": "integer", "format": "int32" @@ -11628,10 +11821,10 @@ }, "security": [ { - "X-Api-Key": [ ] + "X-Api-Key": [] }, { - "apikey": [ ] + "apikey": [] } ] } \ No newline at end of file diff --git a/src/Sonarr.Http/Extensions/RequestExtensions.cs b/src/Sonarr.Http/Extensions/RequestExtensions.cs index 8e7ed9590..772264dfb 100644 --- a/src/Sonarr.Http/Extensions/RequestExtensions.cs +++ b/src/Sonarr.Http/Extensions/RequestExtensions.cs @@ -4,7 +4,6 @@ using System.Linq; using Microsoft.AspNetCore.Http; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Datastore; -using NzbDrone.Core.Exceptions; namespace Sonarr.Http.Extensions { @@ -61,80 +60,6 @@ namespace Sonarr.Http.Extensions return defaultValue; } - public static PagingResource ReadPagingResourceFromRequest(this HttpRequest request) - { - if (!int.TryParse(request.Query["PageSize"].ToString(), out var pageSize)) - { - pageSize = 10; - } - - if (!int.TryParse(request.Query["Page"].ToString(), out var page)) - { - page = 1; - } - - var pagingResource = new PagingResource - { - PageSize = pageSize, - Page = page, - Filters = new List() - }; - - if (request.Query["SortKey"].Any()) - { - var sortKey = request.Query["SortKey"].ToString(); - - if (!VALID_SORT_KEYS.Contains(sortKey) && - !TableMapping.Mapper.IsValidSortKey(sortKey)) - { - throw new BadRequestException($"Invalid sort key {sortKey}"); - } - - pagingResource.SortKey = sortKey; - - if (request.Query["SortDirection"].Any()) - { - pagingResource.SortDirection = request.Query["SortDirection"].ToString() - .Equals("ascending", StringComparison.InvariantCultureIgnoreCase) - ? SortDirection.Ascending - : SortDirection.Descending; - } - } - - // For backwards compatibility with v2 - if (request.Query["FilterKey"].Any()) - { - var filter = new PagingResourceFilter - { - Key = request.Query["FilterKey"].ToString() - }; - - if (request.Query["FilterValue"].Any()) - { - filter.Value = request.Query["FilterValue"].ToString(); - } - - pagingResource.Filters.Add(filter); - } - - // v3 uses filters in key=value format - foreach (var pair in request.Query) - { - if (EXCLUDED_KEYS.Contains(pair.Key)) - { - continue; - } - - pagingResource.Filters.Add(new PagingResourceFilter - { - Key = pair.Key, - Value = pair.Value.ToString() - }); - } - - return pagingResource; - } - public static PagingResource ApplyToPage(this PagingSpec pagingSpec, Func, PagingSpec> function, Converter mapper) { pagingSpec = function(pagingSpec); diff --git a/src/Sonarr.Http/PagingResource.cs b/src/Sonarr.Http/PagingResource.cs index d1c0a6eb7..6559d80ab 100644 --- a/src/Sonarr.Http/PagingResource.cs +++ b/src/Sonarr.Http/PagingResource.cs @@ -1,17 +1,39 @@ using System.Collections.Generic; +using System.ComponentModel; using NzbDrone.Core.Datastore; namespace Sonarr.Http { + public class PagingRequestResource + { + [DefaultValue(1)] + public int? Page { get; set; } + [DefaultValue(10)] + public int? PageSize { get; set; } + public string SortKey { get; set; } + public SortDirection? SortDirection { get; set; } + } + public class PagingResource { public int Page { get; set; } public int PageSize { get; set; } public string SortKey { get; set; } public SortDirection SortDirection { get; set; } - public List Filters { get; set; } public int TotalRecords { get; set; } public List Records { get; set; } + + public PagingResource() + { + } + + public PagingResource(PagingRequestResource requestResource) + { + Page = requestResource.Page ?? 1; + PageSize = requestResource.PageSize ?? 10; + SortKey = requestResource.SortKey; + SortDirection = requestResource.SortDirection ?? SortDirection.Descending; + } } public static class PagingResourceMapper diff --git a/src/Sonarr.Http/PagingResourceFilter.cs b/src/Sonarr.Http/PagingResourceFilter.cs deleted file mode 100644 index 303097a9a..000000000 --- a/src/Sonarr.Http/PagingResourceFilter.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Sonarr.Http -{ - public class PagingResourceFilter - { - public string Key { get; set; } - public string Value { get; set; } - } -}