1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-28 08:58:41 +02:00

Skip duplicate import list exclusions

This commit is contained in:
Bogdan 2024-08-15 06:20:25 +03:00 committed by GitHub
parent d4bd7865f6
commit 9af2f137f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -21,7 +21,10 @@ public ImportListExclusionController(IImportListExclusionService importListExclu
{ {
_importListExclusionService = importListExclusionService; _importListExclusionService = importListExclusionService;
SharedValidator.RuleFor(c => c.TvdbId).NotEmpty().SetValidator(importListExclusionExistsValidator); SharedValidator.RuleFor(c => c.TvdbId).Cascade(CascadeMode.Stop)
.NotEmpty()
.SetValidator(importListExclusionExistsValidator);
SharedValidator.RuleFor(c => c.Title).NotEmpty(); SharedValidator.RuleFor(c => c.Title).NotEmpty();
} }

View File

@ -1,6 +1,7 @@
using FluentValidation.Validators; using FluentValidation.Validators;
using NzbDrone.Core.ImportLists.Exclusions;
namespace NzbDrone.Core.ImportLists.Exclusions namespace Sonarr.Api.V3.ImportLists
{ {
public class ImportListExclusionExistsValidator : PropertyValidator public class ImportListExclusionExistsValidator : PropertyValidator
{ {
@ -20,7 +21,12 @@ protected override bool IsValid(PropertyValidatorContext context)
return true; return true;
} }
return !_importListExclusionService.All().Exists(s => s.TvdbId == (int)context.PropertyValue); if (context.InstanceToValidate is not ImportListExclusionResource listExclusionResource)
{
return true;
}
return !_importListExclusionService.All().Exists(v => v.TvdbId == (int)context.PropertyValue && v.Id != listExclusionResource.Id);
} }
} }
} }