From 87b3a305e90f753d5b2053cdf5c2a7f7b14a55ed Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 29 Aug 2023 05:28:56 +0300 Subject: [PATCH] Fixed: 'includeSeasonImages' parameter to get single series from API Closes #5971 --- src/Sonarr.Api.V3/Series/SeriesController.cs | 32 +++++++++- src/Sonarr.Api.V3/openapi.json | 64 +++++++++++--------- 2 files changed, 67 insertions(+), 29 deletions(-) diff --git a/src/Sonarr.Api.V3/Series/SeriesController.cs b/src/Sonarr.Api.V3/Series/SeriesController.cs index 96bd27952..9f6c6823d 100644 --- a/src/Sonarr.Api.V3/Series/SeriesController.cs +++ b/src/Sonarr.Api.V3/Series/SeriesController.cs @@ -4,6 +4,7 @@ using FluentValidation; using Microsoft.AspNetCore.Mvc; using NzbDrone.Common.Extensions; using NzbDrone.Core.DataAugmentation.Scene; +using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaFiles; @@ -19,6 +20,7 @@ using NzbDrone.Core.Validation; using NzbDrone.Core.Validation.Paths; using NzbDrone.SignalR; using Sonarr.Http; +using Sonarr.Http.Extensions; using Sonarr.Http.REST; using Sonarr.Http.REST.Attributes; @@ -118,12 +120,40 @@ namespace Sonarr.Api.V3.Series return seriesResources; } + [NonAction] + public override ActionResult GetResourceByIdWithErrorHandler(int id) + { + return base.GetResourceByIdWithErrorHandler(id); + } + + [RestGetById] + [Produces("application/json")] + public ActionResult GetResourceByIdWithErrorHandler(int id, [FromQuery] bool includeSeasonImages = false) + { + try + { + return GetSeriesResourceById(id, includeSeasonImages); + } + catch (ModelNotFoundException) + { + return NotFound(); + } + } + protected override SeriesResource GetResourceById(int id) + { + var includeSeasonImages = Request?.GetBooleanQueryParameter("includeSeasonImages", false) ?? false; + + // Parse IncludeImages and use it + return GetSeriesResourceById(id, includeSeasonImages); + } + + private SeriesResource GetSeriesResourceById(int id, bool includeSeasonImages = false) { var series = _seriesService.GetSeries(id); // Parse IncludeImages and use it - return GetSeriesResource(series, false); + return GetSeriesResource(series, includeSeasonImages); } [RestPostById] diff --git a/src/Sonarr.Api.V3/openapi.json b/src/Sonarr.Api.V3/openapi.json index 7dac3b65f..ef261ba3c 100644 --- a/src/Sonarr.Api.V3/openapi.json +++ b/src/Sonarr.Api.V3/openapi.json @@ -6090,6 +6090,42 @@ } }, "/api/v3/series/{id}": { + "get": { + "tags": [ + "Series" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + }, + { + "name": "includeSeasonImages", + "in": "query", + "schema": { + "type": "boolean", + "default": false + } + } + ], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SeriesResource" + } + } + } + } + } + }, "put": { "tags": [ "Series" @@ -6180,34 +6216,6 @@ "description": "Success" } } - }, - "get": { - "tags": [ - "Series" - ], - "parameters": [ - { - "name": "id", - "in": "path", - "required": true, - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "Success", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SeriesResource" - } - } - } - } - } } }, "/api/v3/series/editor": {