Fixed: Ensure validation for Auto Tagging specifications
Co-authored-by: Qstick <qstick@gmail.com>
This commit is contained in:
parent
cd0ea4ce66
commit
97e96537f5
|
@ -1,10 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.AutoTagging;
|
||||
using NzbDrone.Core.AutoTagging.Specifications;
|
||||
using NzbDrone.Core.Validation;
|
||||
using Sonarr.Http;
|
||||
using Sonarr.Http.REST;
|
||||
using Sonarr.Http.REST.Attributes;
|
||||
|
@ -52,6 +54,9 @@ namespace Sonarr.Api.V3.AutoTagging
|
|||
public ActionResult<AutoTaggingResource> Create(AutoTaggingResource autoTagResource)
|
||||
{
|
||||
var model = autoTagResource.ToModel(_specifications);
|
||||
|
||||
Validate(model);
|
||||
|
||||
return Created(_autoTaggingService.Insert(model).Id);
|
||||
}
|
||||
|
||||
|
@ -60,6 +65,9 @@ namespace Sonarr.Api.V3.AutoTagging
|
|||
public ActionResult<AutoTaggingResource> Update(AutoTaggingResource resource)
|
||||
{
|
||||
var model = resource.ToModel(_specifications);
|
||||
|
||||
Validate(model);
|
||||
|
||||
_autoTaggingService.Update(model);
|
||||
|
||||
return Accepted(model.Id);
|
||||
|
@ -85,5 +93,23 @@ namespace Sonarr.Api.V3.AutoTagging
|
|||
|
||||
return schema;
|
||||
}
|
||||
|
||||
private void Validate(AutoTag definition)
|
||||
{
|
||||
foreach (var validationResult in definition.Specifications.Select(spec => spec.Validate()))
|
||||
{
|
||||
VerifyValidationResult(validationResult);
|
||||
}
|
||||
}
|
||||
|
||||
private void VerifyValidationResult(ValidationResult validationResult)
|
||||
{
|
||||
var result = new NzbDroneValidationResult(validationResult.Errors);
|
||||
|
||||
if (!result.IsValid)
|
||||
{
|
||||
throw new ValidationException(result.Errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue