1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-01-03 05:25:10 +00:00

Validation for bulk series editor

Closes #4983
This commit is contained in:
Bogdan 2024-08-26 07:07:20 +03:00
parent 2b8b8ed147
commit 8d3dc0a470
2 changed files with 37 additions and 1 deletions

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentValidation;
using Lidarr.Api.V1.Albums; using Lidarr.Api.V1.Albums;
using Lidarr.Http; using Lidarr.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -16,12 +17,14 @@ public class ArtistEditorController : Controller
private readonly IArtistService _artistService; private readonly IArtistService _artistService;
private readonly IAlbumService _albumService; private readonly IAlbumService _albumService;
private readonly IManageCommandQueue _commandQueueManager; private readonly IManageCommandQueue _commandQueueManager;
private readonly ArtistEditorValidator _artistEditorValidator;
public ArtistEditorController(IArtistService artistService, IAlbumService albumService, IManageCommandQueue commandQueueManager) public ArtistEditorController(IArtistService artistService, IAlbumService albumService, IManageCommandQueue commandQueueManager, ArtistEditorValidator artistEditorValidator)
{ {
_artistService = artistService; _artistService = artistService;
_albumService = albumService; _albumService = albumService;
_commandQueueManager = commandQueueManager; _commandQueueManager = commandQueueManager;
_artistEditorValidator = artistEditorValidator;
} }
[HttpPut] [HttpPut]
@ -80,6 +83,13 @@ public IActionResult SaveAll([FromBody] ArtistEditorResource resource)
break; break;
} }
} }
var validationResult = _artistEditorValidator.Validate(artist);
if (!validationResult.IsValid)
{
throw new ValidationException(validationResult.Errors);
}
} }
if (artistToMove.Any()) if (artistToMove.Any())

View file

@ -0,0 +1,26 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths;
namespace Lidarr.Api.V1.Artist
{
public class ArtistEditorValidator : AbstractValidator<NzbDrone.Core.Music.Artist>
{
public ArtistEditorValidator(RootFolderExistsValidator rootFolderExistsValidator, QualityProfileExistsValidator qualityProfileExistsValidator, MetadataProfileExistsValidator metadataProfileExistsValidator)
{
RuleFor(a => a.RootFolderPath).Cascade(CascadeMode.Stop)
.IsValidPath()
.SetValidator(rootFolderExistsValidator)
.When(a => a.RootFolderPath.IsNotNullOrWhiteSpace());
RuleFor(c => c.QualityProfileId).Cascade(CascadeMode.Stop)
.ValidId()
.SetValidator(qualityProfileExistsValidator);
RuleFor(c => c.MetadataProfileId).Cascade(CascadeMode.Stop)
.ValidId()
.SetValidator(metadataProfileExistsValidator);
}
}
}