1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Api/Episodes/EpisodeModule.cs

47 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-05-31 03:12:20 +03:00
using NzbDrone.Api.REST;
using NzbDrone.Core.MediaFiles;
2013-03-02 22:13:23 +03:00
using NzbDrone.Core.Tv;
using NzbDrone.Api.Extensions;
using System.Linq;
2013-03-02 22:13:23 +03:00
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;
private readonly MediaFileRepository _mediaFileRepository;
2013-03-02 22:13:23 +03:00
public EpisodeModule(IEpisodeService episodeService, MediaFileRepository mediaFileRepository)
2013-03-02 22:13:23 +03:00
: base("/episodes")
{
_episodeService = episodeService;
_mediaFileRepository = mediaFileRepository;
2013-05-31 03:12:20 +03:00
GetResourceAll = GetEpisodes;
UpdateResource = SetMonitored;
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");
}
var resource = ToListResource(() => _episodeService.GetEpisodeBySeries(seriesId.Value))
.LoadSubtype(e => e.EpisodeFileId, _mediaFileRepository);
return resource.ToList();
2013-03-02 22:13:23 +03:00
}
private EpisodeResource SetMonitored(EpisodeResource episodeResource)
{
_episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored);
return episodeResource;
}
2013-03-02 22:13:23 +03:00
}
}