2013-03-04 00:18:43 +01:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-31 02:12:20 +02:00
|
|
|
|
using NzbDrone.Api.REST;
|
2013-06-02 08:41:30 +02:00
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-03-02 20:13:23 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-06-02 08:41:30 +02:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
|
using System.Linq;
|
2013-03-02 20:13:23 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Episodes
|
|
|
|
|
{
|
2013-05-31 02:12:20 +02:00
|
|
|
|
public class EpisodeModule : NzbDroneRestModule<EpisodeResource>
|
2013-03-02 20:13:23 +01:00
|
|
|
|
{
|
2013-04-01 08:22:16 +02:00
|
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-06-02 08:41:30 +02:00
|
|
|
|
private readonly MediaFileRepository _mediaFileRepository;
|
2013-03-02 20:13:23 +01:00
|
|
|
|
|
2013-06-02 08:41:30 +02:00
|
|
|
|
public EpisodeModule(IEpisodeService episodeService, MediaFileRepository mediaFileRepository)
|
2013-03-02 20:13:23 +01:00
|
|
|
|
: base("/episodes")
|
|
|
|
|
{
|
|
|
|
|
_episodeService = episodeService;
|
2013-06-02 08:41:30 +02:00
|
|
|
|
_mediaFileRepository = mediaFileRepository;
|
2013-05-31 02:12:20 +02:00
|
|
|
|
|
|
|
|
|
GetResourceAll = GetEpisodes;
|
2013-03-02 20:13:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-31 02:12:20 +02:00
|
|
|
|
private List<EpisodeResource> GetEpisodes()
|
2013-03-02 20:13:23 +01:00
|
|
|
|
{
|
2013-05-31 02:12:20 +02:00
|
|
|
|
var seriesId = (int?)Request.Query.SeriesId;
|
|
|
|
|
|
|
|
|
|
if (seriesId == null)
|
|
|
|
|
{
|
|
|
|
|
throw new BadRequestException("seriesId is missing");
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-02 08:41:30 +02:00
|
|
|
|
var resource = ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value))
|
|
|
|
|
.LoadSubtype(e => e.EpisodeFileId, _mediaFileRepository);
|
|
|
|
|
|
|
|
|
|
return resource.ToList();
|
2013-03-02 20:13:23 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|