mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-03 05:25:10 +00:00
parent
2b8b8ed147
commit
8d3dc0a470
2 changed files with 37 additions and 1 deletions
|
@ -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())
|
||||||
|
|
26
src/Lidarr.Api.V1/Artist/ArtistEditorValidator.cs
Normal file
26
src/Lidarr.Api.V1/Artist/ArtistEditorValidator.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue