mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
updated add series
This commit is contained in:
@@ -1,27 +1,58 @@
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extentions;
|
||||
using NzbDrone.Api.QualityType;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Api.Series
|
||||
{
|
||||
public class SeriesModule : NzbDroneApiModule
|
||||
{
|
||||
private readonly TvDbProvider _tvDbProvider;
|
||||
private readonly SeriesProvider _seriesProvider;
|
||||
private readonly JobProvider _jobProvider;
|
||||
|
||||
public SeriesModule(TvDbProvider tvDbProvider)
|
||||
public SeriesModule(SeriesProvider seriesProvider, JobProvider jobProvider)
|
||||
: base("/Series")
|
||||
{
|
||||
_tvDbProvider = tvDbProvider;
|
||||
Get["/lookup"] = x => GetQualityType();
|
||||
_seriesProvider = seriesProvider;
|
||||
_jobProvider = jobProvider;
|
||||
Post["/"] = x => AddSeries();
|
||||
}
|
||||
|
||||
|
||||
private Response GetQualityType()
|
||||
private Response AddSeries()
|
||||
{
|
||||
var tvDbResults = _tvDbProvider.SearchSeries((string)Request.Query.term);
|
||||
return tvDbResults.AsResponse();
|
||||
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;
|
||||
}
|
||||
|
||||
public SeriesValidator()
|
||||
{
|
||||
RuleSet("POST", () =>
|
||||
{
|
||||
RuleFor(s => s.SeriesId).GreaterThan(0);
|
||||
RuleFor(s => s.Path).NotEmpty().Must(_diskProvider.FolderExists);
|
||||
RuleFor(s => s.QualityProfileId).GreaterThan(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user