Validation for bulk movies editor

pull/10286/head
Bogdan 3 months ago committed by Qstick
parent 6eeed96d12
commit 68c20713e5

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
@ -22,6 +23,7 @@ namespace Radarr.Api.V3.Movies
private readonly IMapCoversToLocal _coverMapper;
private readonly IConfigService _configService;
private readonly IManageCommandQueue _commandQueueManager;
private readonly MovieEditorValidator _movieEditorValidator;
private readonly IUpgradableSpecification _upgradableSpecification;
public MovieEditorController(IMovieService movieService,
@ -29,6 +31,7 @@ namespace Radarr.Api.V3.Movies
IMapCoversToLocal coverMapper,
IConfigService configService,
IManageCommandQueue commandQueueManager,
MovieEditorValidator movieEditorValidator,
IUpgradableSpecification upgradableSpecification)
{
_movieService = movieService;
@ -36,6 +39,7 @@ namespace Radarr.Api.V3.Movies
_coverMapper = coverMapper;
_configService = configService;
_commandQueueManager = commandQueueManager;
_movieEditorValidator = movieEditorValidator;
_upgradableSpecification = upgradableSpecification;
}
@ -90,6 +94,13 @@ namespace Radarr.Api.V3.Movies
break;
}
}
var validationResult = _movieEditorValidator.Validate(movie);
if (!validationResult.IsValid)
{
throw new ValidationException(validationResult.Errors);
}
}
if (resource.MoveFiles && moviesToMove.Any())

@ -0,0 +1,23 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;
namespace Radarr.Api.V3.Movies
{
public class MovieEditorValidator : AbstractValidator<Movie>
{
public MovieEditorValidator(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…
Cancel
Save