mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-27 02:43:57 +02:00
Validation for bulk series editor
This commit is contained in:
parent
e6f82270a9
commit
8b253c36ea
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
@ -14,11 +15,13 @@ public class SeriesEditorController : Controller
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
private readonly SeriesEditorValidator _seriesEditorValidator;
|
||||
|
||||
public SeriesEditorController(ISeriesService seriesService, IManageCommandQueue commandQueueManager)
|
||||
public SeriesEditorController(ISeriesService seriesService, IManageCommandQueue commandQueueManager, SeriesEditorValidator seriesEditorValidator)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
_seriesEditorValidator = seriesEditorValidator;
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
@ -58,10 +61,10 @@ public object SaveAll([FromBody] SeriesEditorResource resource)
|
||||
{
|
||||
series.RootFolderPath = resource.RootFolderPath;
|
||||
seriesToMove.Add(new BulkMoveSeries
|
||||
{
|
||||
SeriesId = series.Id,
|
||||
SourcePath = series.Path
|
||||
});
|
||||
{
|
||||
SeriesId = series.Id,
|
||||
SourcePath = series.Path
|
||||
});
|
||||
}
|
||||
|
||||
if (resource.Tags != null)
|
||||
@ -82,15 +85,22 @@ public object SaveAll([FromBody] SeriesEditorResource resource)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var validationResult = _seriesEditorValidator.Validate(series);
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
throw new ValidationException(validationResult.Errors);
|
||||
}
|
||||
}
|
||||
|
||||
if (resource.MoveFiles && seriesToMove.Any())
|
||||
{
|
||||
_commandQueueManager.Push(new BulkMoveSeriesCommand
|
||||
{
|
||||
DestinationRootFolder = resource.RootFolderPath,
|
||||
Series = seriesToMove
|
||||
});
|
||||
{
|
||||
DestinationRootFolder = resource.RootFolderPath,
|
||||
Series = seriesToMove
|
||||
});
|
||||
}
|
||||
|
||||
return Accepted(_seriesService.UpdateSeries(seriesToUpdate, !resource.MoveFiles).ToResource());
|
||||
|
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 New Issue
Block a user