New: TVDB ID filter when getting series from API

Closes #2486
This commit is contained in:
Mark McDowall 2019-05-12 16:14:56 -07:00
parent 98b1a7681b
commit 068eb33bf6
2 changed files with 23 additions and 1 deletions

View File

@ -99,9 +99,19 @@ namespace Sonarr.Api.V3.Series
private List<SeriesResource> AllSeries()
{
var tvdbId = Request.GetIntegerQueryParameter("tvdbId");
var includeSeasonImages = Request.GetBooleanQueryParameter("includeSeasonImages");
var seriesStats = _seriesStatisticsService.SeriesStatistics();
var seriesResources = _seriesService.GetAllSeries().Select(s => s.ToResource(includeSeasonImages)).ToList();
var seriesResources = new List<SeriesResource>();
if (tvdbId > 0)
{
seriesResources.AddIfNotNull(_seriesService.FindByTvdbId(tvdbId).ToResource(includeSeasonImages));
}
else
{
seriesResources.AddRange(_seriesService.GetAllSeries().Select(s => s.ToResource(includeSeasonImages)));
}
MapCoversToLocal(seriesResources.ToArray());
LinkSeriesStatistics(seriesResources, seriesStats);

View File

@ -54,5 +54,17 @@ namespace Sonarr.Http.Extensions
return defaultValue;
}
public static int GetIntegerQueryParameter(this Request request, string parameter, int defaultValue = 0)
{
var parameterValue = request.Query[parameter];
if (parameterValue.HasValue)
{
return int.Parse(parameterValue.Value);
}
return defaultValue;
}
}
}