2013-06-04 03:59:24 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NzbDrone.Api.Episodes;
|
|
|
|
|
using NzbDrone.Common;
|
2013-05-14 03:21:37 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-03-21 03:02:57 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Missing
|
|
|
|
|
{
|
2013-05-14 03:21:37 +00:00
|
|
|
|
public class MissingModule : NzbDroneRestModule<EpisodeResource>
|
2013-03-21 03:02:57 +00:00
|
|
|
|
{
|
2013-04-01 06:22:16 +00:00
|
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-06-04 03:59:24 +00:00
|
|
|
|
private readonly SeriesService _seriesService;
|
2013-03-21 03:02:57 +00:00
|
|
|
|
|
2013-06-04 03:59:24 +00:00
|
|
|
|
public MissingModule(IEpisodeService episodeService, SeriesService seriesService)
|
2013-05-14 03:21:37 +00:00
|
|
|
|
:base("missing")
|
2013-03-21 03:02:57 +00:00
|
|
|
|
{
|
|
|
|
|
_episodeService = episodeService;
|
2013-06-04 03:59:24 +00:00
|
|
|
|
_seriesService = seriesService;
|
2013-05-13 06:12:19 +00:00
|
|
|
|
GetResourcePaged = GetMissingEpisodes;
|
2013-03-21 03:02:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 03:21:37 +00:00
|
|
|
|
private PagingResource<EpisodeResource> GetMissingEpisodes(PagingResource<EpisodeResource> pagingResource)
|
2013-03-21 03:02:57 +00:00
|
|
|
|
{
|
2013-05-02 05:50:34 +00:00
|
|
|
|
var pagingSpec = new PagingSpec<Episode>
|
2013-05-13 06:12:19 +00:00
|
|
|
|
{
|
|
|
|
|
Page = pagingResource.Page,
|
|
|
|
|
PageSize = pagingResource.PageSize,
|
|
|
|
|
SortKey = pagingResource.SortKey,
|
|
|
|
|
SortDirection = pagingResource.SortDirection
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-04 03:59:24 +00:00
|
|
|
|
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;
|
2013-03-21 03:02:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|