mirror of https://github.com/Sonarr/Sonarr
Calendar and Missing join series in API
This commit is contained in:
parent
2e3863895c
commit
047e53179d
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Api.Episodes;
|
||||
using NzbDrone.Api.Mapping;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Api.Calendar
|
||||
|
@ -9,11 +11,13 @@ namespace NzbDrone.Api.Calendar
|
|||
public class CalendarModule : NzbDroneRestModule<EpisodeResource>
|
||||
{
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly SeriesService _seriesService;
|
||||
|
||||
public CalendarModule(IEpisodeService episodeService)
|
||||
public CalendarModule(IEpisodeService episodeService, SeriesService seriesService)
|
||||
: base("/calendar")
|
||||
{
|
||||
_episodeService = episodeService;
|
||||
_seriesService = seriesService;
|
||||
|
||||
GetResourceAll = GetPaged;
|
||||
}
|
||||
|
@ -27,12 +31,15 @@ namespace NzbDrone.Api.Calendar
|
|||
var queryEnd = Request.Query.End;
|
||||
|
||||
if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value);
|
||||
|
||||
if (queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value);
|
||||
|
||||
var episodes = _episodeService.EpisodesBetweenDates(start, end);
|
||||
var episodeResources = ToListResource(() => episodes);
|
||||
|
||||
return ToListResource(() => episodes);
|
||||
var series = _seriesService.GetSeriesInList(episodeResources.SelectDistinct(e => e.SeriesId));
|
||||
episodeResources.Join(series, episode => episode.SeriesId, s => s.Id, episode => episode.Series);
|
||||
|
||||
return episodeResources;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using NzbDrone.Api.Episodes;
|
||||
using System.Linq;
|
||||
using NzbDrone.Api.Episodes;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
|
@ -7,11 +9,13 @@ namespace NzbDrone.Api.Missing
|
|||
public class MissingModule : NzbDroneRestModule<EpisodeResource>
|
||||
{
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly SeriesService _seriesService;
|
||||
|
||||
public MissingModule(IEpisodeService episodeService)
|
||||
public MissingModule(IEpisodeService episodeService, SeriesService seriesService)
|
||||
:base("missing")
|
||||
{
|
||||
_episodeService = episodeService;
|
||||
_seriesService = seriesService;
|
||||
GetResourcePaged = GetMissingEpisodes;
|
||||
}
|
||||
|
||||
|
@ -25,7 +29,12 @@ namespace NzbDrone.Api.Missing
|
|||
SortDirection = pagingResource.SortDirection
|
||||
};
|
||||
|
||||
return ApplyToPage(_episodeService.EpisodesWithoutFiles, pagingSpec);
|
||||
var episodeResources = ApplyToPage(_episodeService.EpisodesWithoutFiles, pagingSpec);
|
||||
|
||||
var series = _seriesService.GetSeriesInList(episodeResources.Records.SelectDistinct(e => e.SeriesId));
|
||||
episodeResources.Records.Join(series, episode => episode.SeriesId, s => s.Id, episode => episode.Series);
|
||||
|
||||
return episodeResources;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static IEnumerable<TKey> SelectDistinct<TOuter, TKey>(this IEnumerable<TOuter> outer, Func<TOuter, TKey> outerKeySelector)
|
||||
{
|
||||
return outer.Select(outerKeySelector).Distinct();
|
||||
}
|
||||
|
||||
public static IEnumerable<TOuter> Join<TOuter, TInner, TKey, TProperty>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Expression<Func<TOuter, TProperty>> outerProperty)
|
||||
{
|
||||
var outerList = outer.ToList();
|
||||
var innerList = inner.ToList();
|
||||
|
||||
foreach (var outerElement in outerList)
|
||||
{
|
||||
var outerKey = outerKeySelector(outerElement);
|
||||
|
||||
foreach (var innerElement in innerList)
|
||||
{
|
||||
var innerKey = innerKeySelector(innerElement);
|
||||
|
||||
if (innerKey.Equals(outerKey))
|
||||
{
|
||||
var prop = (PropertyInfo)((MemberExpression)outerProperty.Body).Member;
|
||||
prop.SetValue(outerElement, innerElement, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return outerList;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -84,6 +84,7 @@
|
|||
<Compile Include="Composition\Container.cs" />
|
||||
<Compile Include="Composition\IContainer.cs" />
|
||||
<Compile Include="Composition\ContainerBuilderBase.cs" />
|
||||
<Compile Include="EnumerableExtensions.cs" />
|
||||
<Compile Include="EnsureThat\Ensure.cs" />
|
||||
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" />
|
||||
<Compile Include="EnsureThat\EnsureCollectionExtensions.cs" />
|
||||
|
|
|
@ -20,6 +20,7 @@ define([
|
|||
{
|
||||
name : 'series.Title',
|
||||
label : 'Series Title',
|
||||
sortable : false,
|
||||
cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' })
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue