Fixed: Add metadata profile exists validator

pull/145/head
Qstick 7 years ago
parent db03f43e30
commit 56f6b923e1

@ -35,20 +35,19 @@ namespace Lidarr.Api.V1.Artist
private readonly IAddArtistService _addArtistService;
private readonly IArtistStatisticsService _artistStatisticsService;
private readonly IMapCoversToLocal _coverMapper;
private readonly IAlbumService _albumService;
public ArtistModule(IBroadcastSignalRMessage signalRBroadcaster,
IArtistService artistService,
IAddArtistService addArtistService,
IArtistStatisticsService artistStatisticsService,
IMapCoversToLocal coverMapper,
IAlbumService albumService,
RootFolderValidator rootFolderValidator,
ArtistPathValidator artistPathValidator,
ArtistExistsValidator artistExistsValidator,
ArtistAncestorValidator artistAncestorValidator,
ProfileExistsValidator profileExistsValidator,
LanguageProfileExistsValidator languageProfileExistsValidator
LanguageProfileExistsValidator languageProfileExistsValidator,
MetadataProfileExistsValidator metadataProfileExistsValidator
)
: base(signalRBroadcaster)
{
@ -57,7 +56,6 @@ namespace Lidarr.Api.V1.Artist
_artistStatisticsService = artistStatisticsService;
_coverMapper = coverMapper;
_albumService = albumService;
GetResourceAll = AllArtists;
GetResourceById = GetArtist;
@ -77,6 +75,7 @@ namespace Lidarr.Api.V1.Artist
SharedValidator.RuleFor(s => s.QualityProfileId).SetValidator(profileExistsValidator);
SharedValidator.RuleFor(s => s.LanguageProfileId).SetValidator(languageProfileExistsValidator);
SharedValidator.RuleFor(s => s.MetadataProfileId).SetValidator(metadataProfileExistsValidator);
PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace());
PostValidator.RuleFor(s => s.RootFolderPath).IsValidPath().When(s => s.Path.IsNullOrWhiteSpace());

@ -1069,6 +1069,7 @@
<Compile Include="Validation\FolderValidator.cs" />
<Compile Include="Validation\IpValidation.cs" />
<Compile Include="Validation\LanguageProfileExistsValidator.cs" />
<Compile Include="Validation\MetadataProfileExistsValidator.cs" />
<Compile Include="Validation\NzbDroneValidationExtensions.cs" />
<Compile Include="Validation\NzbDroneValidationFailure.cs" />
<Compile Include="Validation\NzbDroneValidationResult.cs" />

@ -0,0 +1,23 @@
using FluentValidation.Validators;
using NzbDrone.Core.Profiles.Metadata;
namespace NzbDrone.Core.Validation
{
public class MetadataProfileExistsValidator : PropertyValidator
{
private readonly IMetadataProfileService _profileService;
public MetadataProfileExistsValidator(IMetadataProfileService profileService)
: base("Metadata profile does not exist")
{
_profileService = profileService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
return _profileService.Exists((int)context.PropertyValue);
}
}
}
Loading…
Cancel
Save