2013-07-09 17:41:42 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-08-27 05:20:03 +02:00
|
|
|
|
using NzbDrone.Api.Mapping;
|
2013-03-03 23:26:41 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Seasons
|
|
|
|
|
{
|
2013-07-09 17:41:42 +02:00
|
|
|
|
public class SeasonModule : NzbDroneRestModule<SeasonResource>
|
2013-03-03 23:26:41 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly ISeasonService _seasonService;
|
|
|
|
|
|
|
|
|
|
public SeasonModule(ISeasonService seasonService)
|
2013-07-09 17:41:42 +02:00
|
|
|
|
: base("/season")
|
2013-03-03 23:26:41 +01:00
|
|
|
|
{
|
|
|
|
|
_seasonService = seasonService;
|
|
|
|
|
|
2013-07-09 17:41:42 +02:00
|
|
|
|
GetResourceAll = GetSeasons;
|
2013-08-27 05:20:03 +02:00
|
|
|
|
GetResourceById = GetSeason;
|
2013-08-26 07:14:55 +02:00
|
|
|
|
UpdateResource = Update;
|
2013-08-05 11:09:41 +02:00
|
|
|
|
|
|
|
|
|
Post["/pass"] = x => SetSeasonPass();
|
2013-03-03 23:26:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-09 17:41:42 +02:00
|
|
|
|
private List<SeasonResource> GetSeasons()
|
2013-03-03 23:26:41 +01:00
|
|
|
|
{
|
|
|
|
|
var seriesId = Request.Query.SeriesId;
|
|
|
|
|
|
2013-08-05 11:09:41 +02:00
|
|
|
|
if (seriesId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return ToListResource<Season>(() => _seasonService.GetSeasonsBySeries(seriesId));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 07:14:55 +02:00
|
|
|
|
return ToListResource(() => _seasonService.GetAllSeasons());
|
2013-03-03 23:26:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-27 05:20:03 +02:00
|
|
|
|
private SeasonResource GetSeason(int id)
|
|
|
|
|
{
|
|
|
|
|
return _seasonService.Get(id).InjectTo<SeasonResource>();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 07:14:55 +02:00
|
|
|
|
private void Update(SeasonResource seasonResource)
|
2013-07-09 17:41:42 +02:00
|
|
|
|
{
|
|
|
|
|
_seasonService.SetMonitored(seasonResource.SeriesId, seasonResource.SeasonNumber, seasonResource.Monitored);
|
|
|
|
|
}
|
2013-08-05 11:09:41 +02:00
|
|
|
|
|
|
|
|
|
private List<SeasonResource> SetSeasonPass()
|
|
|
|
|
{
|
|
|
|
|
var seriesId = Request.Form.SeriesId;
|
|
|
|
|
var seasonNumber = Request.Form.SeasonNumber;
|
|
|
|
|
|
|
|
|
|
return ToListResource<Season>(() => _seasonService.SetSeasonPass(seriesId, seasonNumber));
|
|
|
|
|
}
|
2013-07-09 17:41:42 +02:00
|
|
|
|
}
|
2013-03-03 23:26:41 +01:00
|
|
|
|
}
|