mirror of
https://github.com/Sonarr/Sonarr
synced 2025-01-03 13:45:02 +00:00
Validation for bulk series editor
This commit is contained in:
parent
e6f82270a9
commit
8b253c36ea
2 changed files with 41 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using FluentValidation;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
|
@ -14,11 +15,13 @@ namespace Sonarr.Api.V3.Series
|
||||||
{
|
{
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly ISeriesService _seriesService;
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
|
private readonly SeriesEditorValidator _seriesEditorValidator;
|
||||||
|
|
||||||
public SeriesEditorController(ISeriesService seriesService, IManageCommandQueue commandQueueManager)
|
public SeriesEditorController(ISeriesService seriesService, IManageCommandQueue commandQueueManager, SeriesEditorValidator seriesEditorValidator)
|
||||||
{
|
{
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
_commandQueueManager = commandQueueManager;
|
_commandQueueManager = commandQueueManager;
|
||||||
|
_seriesEditorValidator = seriesEditorValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
|
@ -82,6 +85,13 @@ namespace Sonarr.Api.V3.Series
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var validationResult = _seriesEditorValidator.Validate(series);
|
||||||
|
|
||||||
|
if (!validationResult.IsValid)
|
||||||
|
{
|
||||||
|
throw new ValidationException(validationResult.Errors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource.MoveFiles && seriesToMove.Any())
|
if (resource.MoveFiles && seriesToMove.Any())
|
||||||
|
|
22
src/Sonarr.Api.V3/Series/SeriesEditorValidator.cs
Normal file
22
src/Sonarr.Api.V3/Series/SeriesEditorValidator.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using FluentValidation;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
using NzbDrone.Core.Validation.Paths;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V3.Series
|
||||||
|
{
|
||||||
|
public class SeriesEditorValidator : AbstractValidator<NzbDrone.Core.Tv.Series>
|
||||||
|
{
|
||||||
|
public SeriesEditorValidator(RootFolderExistsValidator rootFolderExistsValidator, QualityProfileExistsValidator qualityProfileExistsValidator)
|
||||||
|
{
|
||||||
|
RuleFor(s => s.RootFolderPath).Cascade(CascadeMode.Stop)
|
||||||
|
.IsValidPath()
|
||||||
|
.SetValidator(rootFolderExistsValidator)
|
||||||
|
.When(s => s.RootFolderPath.IsNotNullOrWhiteSpace());
|
||||||
|
|
||||||
|
RuleFor(c => c.QualityProfileId).Cascade(CascadeMode.Stop)
|
||||||
|
.ValidId()
|
||||||
|
.SetValidator(qualityProfileExistsValidator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue