You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Radarr/NzbDrone.Api/Episodes/EpisodeModule.cs

47 lines
1.4 KiB

using System.Collections.Generic;
using NzbDrone.Api.REST;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv;
using NzbDrone.Api.Extensions;
using System.Linq;
namespace NzbDrone.Api.Episodes
{
public class EpisodeModule : NzbDroneRestModule<EpisodeResource>
{
12 years ago
private readonly IEpisodeService _episodeService;
private readonly MediaFileRepository _mediaFileRepository;
public EpisodeModule(IEpisodeService episodeService, MediaFileRepository mediaFileRepository)
: base("/episodes")
{
_episodeService = episodeService;
_mediaFileRepository = mediaFileRepository;
GetResourceAll = GetEpisodes;
UpdateResource = SetMonitored;
}
private List<EpisodeResource> GetEpisodes()
{
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();
}
private EpisodeResource SetMonitored(EpisodeResource episodeResource)
{
_episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored);
return episodeResource;
}
}
}