Radarr/src/NzbDrone.Api/Episodes/EpisodeModule.cs

58 lines
2.0 KiB
C#
Raw Normal View History

2013-11-20 00:42:17 +00:00
using System.Collections.Generic;
2013-05-31 00:12:20 +00:00
using NzbDrone.Api.REST;
2013-09-30 15:09:47 +00:00
using NzbDrone.Core.Messaging.Commands;
2013-03-02 19:13:23 +00:00
using NzbDrone.Core.Tv;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.DecisionEngine;
2013-03-02 19:13:23 +00:00
namespace NzbDrone.Api.Episodes
{
public class EpisodeModule : EpisodeModuleWithSignalR
2013-03-02 19:13:23 +00:00
{
private readonly ISeriesService _seriesService;
2013-04-01 06:22:16 +00:00
private readonly IEpisodeService _episodeService;
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
2013-03-02 19:13:23 +00:00
public EpisodeModule(ICommandExecutor commandExecutor, ISeriesService seriesService, IEpisodeService episodeService, IQualityUpgradableSpecification qualityUpgradableSpecification)
2014-06-28 16:45:50 +00:00
: base(episodeService, commandExecutor)
2013-03-02 19:13:23 +00:00
{
_seriesService = seriesService;
2013-03-02 19:13:23 +00:00
_episodeService = episodeService;
_qualityUpgradableSpecification = qualityUpgradableSpecification;
2013-05-31 00:12:20 +00:00
GetResourceAll = GetEpisodes;
UpdateResource = SetMonitored;
2013-03-02 19:13:23 +00:00
}
2013-05-31 00:12:20 +00:00
private List<EpisodeResource> GetEpisodes()
2013-03-02 19:13:23 +00:00
{
2013-05-31 00:12:20 +00:00
var seriesId = (int?)Request.Query.SeriesId;
if (seriesId == null)
{
throw new BadRequestException("seriesId is missing");
}
var series = _seriesService.GetSeries(seriesId.Value);
var resources = new List<EpisodeResource>();
foreach (var episode in _episodeService.GetEpisodeBySeries(seriesId.Value))
{
var resource = episode.InjectTo<EpisodeResource>();
if (episode.EpisodeFile.IsLoaded)
{
resource.EpisodeFile.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(series.Profile.Value, episode.EpisodeFile.Value.Quality);
}
resources.Add(resource);
}
return resources;
2013-03-02 19:13:23 +00:00
}
private void SetMonitored(EpisodeResource episodeResource)
{
_episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored);
}
2013-03-02 19:13:23 +00:00
}
}