2013-01-20 04:37:48 +03:00
|
|
|
using System.Linq;
|
2013-01-28 21:06:54 +03:00
|
|
|
using FluentValidation;
|
2013-01-20 04:37:48 +03:00
|
|
|
using Nancy;
|
2013-01-25 22:03:28 +03:00
|
|
|
using NzbDrone.Api.Extentions;
|
2013-01-28 21:06:54 +03:00
|
|
|
using NzbDrone.Common;
|
|
|
|
using NzbDrone.Core.Jobs;
|
2013-01-20 04:37:48 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Series
|
|
|
|
{
|
|
|
|
public class SeriesModule : NzbDroneApiModule
|
|
|
|
{
|
2013-01-28 21:06:54 +03:00
|
|
|
private readonly SeriesProvider _seriesProvider;
|
|
|
|
private readonly JobProvider _jobProvider;
|
2013-01-20 04:37:48 +03:00
|
|
|
|
2013-01-28 21:06:54 +03:00
|
|
|
public SeriesModule(SeriesProvider seriesProvider, JobProvider jobProvider)
|
2013-01-20 04:37:48 +03:00
|
|
|
: base("/Series")
|
|
|
|
{
|
2013-01-28 21:06:54 +03:00
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
_jobProvider = jobProvider;
|
|
|
|
Post["/"] = x => AddSeries();
|
2013-01-20 04:37:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-28 21:06:54 +03:00
|
|
|
private Response AddSeries()
|
2013-01-20 04:37:48 +03:00
|
|
|
{
|
2013-01-28 21:06:54 +03: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 04:37:48 +03:00
|
|
|
}
|
2013-01-28 21:06:54 +03: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 04:37:48 +03:00
|
|
|
}
|
|
|
|
}
|