Fixed: Ensure validation for Auto Tagging specifications

pull/8887/head
Bogdan 11 months ago
parent 430ea81937
commit d5c1f58839

@ -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 Radarr.Http;
using Radarr.Http.REST;
using Radarr.Http.REST.Attributes;
@ -52,6 +54,9 @@ namespace Radarr.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 Radarr.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 Radarr.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…
Cancel
Save