2013-03-04 02:18:43 +03:00
|
|
|
using System.Collections.Generic;
|
2013-08-27 06:20:03 +03:00
|
|
|
using NzbDrone.Api.Mapping;
|
2013-05-31 03:12:20 +03:00
|
|
|
using NzbDrone.Api.REST;
|
2013-03-02 22:13:23 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Episodes
|
|
|
|
{
|
2013-05-31 03:12:20 +03:00
|
|
|
public class EpisodeModule : NzbDroneRestModule<EpisodeResource>
|
2013-03-02 22:13:23 +03:00
|
|
|
{
|
2013-04-01 09:22:16 +03:00
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-03-02 22:13:23 +03:00
|
|
|
|
2013-08-22 03:56:25 +03:00
|
|
|
public EpisodeModule(IEpisodeService episodeService)
|
2013-03-02 22:13:23 +03:00
|
|
|
: base("/episodes")
|
|
|
|
{
|
|
|
|
_episodeService = episodeService;
|
2013-05-31 03:12:20 +03:00
|
|
|
|
|
|
|
GetResourceAll = GetEpisodes;
|
2013-07-09 18:41:42 +03:00
|
|
|
UpdateResource = SetMonitored;
|
2013-08-27 06:20:03 +03:00
|
|
|
GetResourceById = GetEpisode;
|
2013-03-02 22:13:23 +03:00
|
|
|
}
|
|
|
|
|
2013-05-31 03:12:20 +03:00
|
|
|
private List<EpisodeResource> GetEpisodes()
|
2013-03-02 22:13:23 +03:00
|
|
|
{
|
2013-05-31 03:12:20 +03:00
|
|
|
var seriesId = (int?)Request.Query.SeriesId;
|
|
|
|
|
|
|
|
if (seriesId == null)
|
|
|
|
{
|
|
|
|
throw new BadRequestException("seriesId is missing");
|
|
|
|
}
|
|
|
|
|
2013-08-22 03:56:25 +03:00
|
|
|
return ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value));
|
2013-03-02 22:13:23 +03:00
|
|
|
}
|
2013-07-09 18:41:42 +03:00
|
|
|
|
2013-08-26 08:14:55 +03:00
|
|
|
private void SetMonitored(EpisodeResource episodeResource)
|
2013-07-09 18:41:42 +03:00
|
|
|
{
|
|
|
|
_episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored);
|
|
|
|
}
|
2013-08-27 06:20:03 +03:00
|
|
|
|
|
|
|
private EpisodeResource GetEpisode(int id)
|
|
|
|
{
|
|
|
|
return _episodeService.GetEpisode(id).InjectTo<EpisodeResource>();
|
|
|
|
}
|
2013-03-02 22:13:23 +03:00
|
|
|
}
|
|
|
|
}
|