Fixed: Add metadata profile exists validator

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

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

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