mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 07:12:40 +00:00
Fixed: Ensure validation for Auto Tagging specifications
Co-authored-by: Qstick <qstick@gmail.com> (cherry picked from commit 97e96537f5a656f368ac07b8b28c84683d105d9f)
This commit is contained in:
parent
362bd42cb8
commit
f2c625d17e
1 changed files with 26 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
using FluentValidation.Results;
|
||||||
using Lidarr.Http;
|
using Lidarr.Http;
|
||||||
using Lidarr.Http.REST;
|
using Lidarr.Http.REST;
|
||||||
using Lidarr.Http.REST.Attributes;
|
using Lidarr.Http.REST.Attributes;
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.AutoTagging;
|
using NzbDrone.Core.AutoTagging;
|
||||||
using NzbDrone.Core.AutoTagging.Specifications;
|
using NzbDrone.Core.AutoTagging.Specifications;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
namespace Lidarr.Api.V3.AutoTagging
|
namespace Lidarr.Api.V3.AutoTagging
|
||||||
{
|
{
|
||||||
|
@ -52,6 +54,9 @@ public override AutoTaggingResource GetResourceById(int id)
|
||||||
public ActionResult<AutoTaggingResource> Create(AutoTaggingResource autoTagResource)
|
public ActionResult<AutoTaggingResource> Create(AutoTaggingResource autoTagResource)
|
||||||
{
|
{
|
||||||
var model = autoTagResource.ToModel(_specifications);
|
var model = autoTagResource.ToModel(_specifications);
|
||||||
|
|
||||||
|
Validate(model);
|
||||||
|
|
||||||
return Created(_autoTaggingService.Insert(model).Id);
|
return Created(_autoTaggingService.Insert(model).Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +65,9 @@ public ActionResult<AutoTaggingResource> Create(AutoTaggingResource autoTagResou
|
||||||
public ActionResult<AutoTaggingResource> Update(AutoTaggingResource resource)
|
public ActionResult<AutoTaggingResource> Update(AutoTaggingResource resource)
|
||||||
{
|
{
|
||||||
var model = resource.ToModel(_specifications);
|
var model = resource.ToModel(_specifications);
|
||||||
|
|
||||||
|
Validate(model);
|
||||||
|
|
||||||
_autoTaggingService.Update(model);
|
_autoTaggingService.Update(model);
|
||||||
|
|
||||||
return Accepted(model.Id);
|
return Accepted(model.Id);
|
||||||
|
@ -85,5 +93,23 @@ public object GetTemplates()
|
||||||
|
|
||||||
return schema;
|
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 a new issue