1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-29 03:05:49 +00:00
Sonarr/NzbDrone.Api/Series/SeriesModule.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2013-01-20 01:37:48 +00:00
using System.Linq;
2013-01-28 18:06:54 +00:00
using FluentValidation;
2013-01-20 01:37:48 +00:00
using Nancy;
using NzbDrone.Api.Extentions;
2013-01-28 18:06:54 +00:00
using NzbDrone.Common;
using NzbDrone.Core.Jobs;
2013-01-20 01:37:48 +00:00
using NzbDrone.Core.Providers;
namespace NzbDrone.Api.Series
{
public class SeriesModule : NzbDroneApiModule
{
2013-01-28 18:06:54 +00:00
private readonly SeriesProvider _seriesProvider;
private readonly JobProvider _jobProvider;
2013-01-20 01:37:48 +00:00
2013-01-28 18:06:54 +00:00
public SeriesModule(SeriesProvider seriesProvider, JobProvider jobProvider)
2013-01-20 01:37:48 +00:00
: base("/Series")
{
2013-01-28 18:06:54 +00:00
_seriesProvider = seriesProvider;
_jobProvider = jobProvider;
Post["/"] = x => AddSeries();
2013-01-20 01:37:48 +00:00
}
2013-01-28 18:06:54 +00:00
private Response AddSeries()
2013-01-20 01:37:48 +00:00
{
2013-01-28 18:06:54 +00:00
var request = Request.Body.FromJson<Core.Repository.Series>();
_seriesProvider.AddSeries("", request.Path, request.SeriesId, request.QualityProfileId, null);
_jobProvider.QueueJob(typeof(ImportNewSeriesJob));
return new Response { StatusCode = HttpStatusCode.Created };
}
}
public class SeriesValidator : AbstractValidator<Core.Repository.Series>
{
private readonly DiskProvider _diskProvider;
public SeriesValidator(DiskProvider diskProvider)
{
_diskProvider = diskProvider;
2013-01-20 01:37:48 +00:00
}
2013-01-28 18:06:54 +00:00
public SeriesValidator()
{
RuleSet("POST", () =>
{
RuleFor(s => s.SeriesId).GreaterThan(0);
RuleFor(s => s.Path).NotEmpty().Must(_diskProvider.FolderExists);
RuleFor(s => s.QualityProfileId).GreaterThan(0);
});
}
2013-01-20 01:37:48 +00:00
}
}