Improve validation message for AuthorFolderAsRootFolderValidator

(cherry picked from commit a117001de673e80abd90d54a34a7c86292b3a649)
This commit is contained in:
Bogdan
2023-05-20 22:22:04 +03:00
parent f819e582cf
commit 59a7605385

View File

@@ -15,7 +15,7 @@ namespace Readarr.Api.V1.Author
_fileNameBuilder = fileNameBuilder;
}
protected override string GetDefaultMessageTemplate() => "Root folder path contains author folder";
protected override string GetDefaultMessageTemplate() => "Root folder path '{rootFolderPath}' contains author folder '{authorFolder}'";
protected override bool IsValid(PropertyValidatorContext context)
{
@@ -24,9 +24,7 @@ namespace Readarr.Api.V1.Author
return true;
}
var authorResource = context.ParentContext.InstanceToValidate as AuthorResource;
if (authorResource == null)
if (context.ParentContext.InstanceToValidate is not AuthorResource authorResource)
{
return true;
}
@@ -36,6 +34,9 @@ namespace Readarr.Api.V1.Author
var author = authorResource.ToModel();
var authorFolder = _fileNameBuilder.GetAuthorFolder(author);
context.MessageFormatter.AppendArgument("rootFolderPath", rootFolderPath);
context.MessageFormatter.AppendArgument("authorFolder", authorFolder);
if (authorFolder == rootFolder)
{
return false;