mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-16 23:39:44 +02:00
Fixed: Ensure validation for Auto Tagging specifications
This commit is contained in:
parent
430ea81937
commit
d5c1f58839
@ -1,10 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
using FluentValidation.Results;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
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;
|
||||||
using Radarr.Http;
|
using Radarr.Http;
|
||||||
using Radarr.Http.REST;
|
using Radarr.Http.REST;
|
||||||
using Radarr.Http.REST.Attributes;
|
using Radarr.Http.REST.Attributes;
|
||||||
@ -52,6 +54,9 @@ protected 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 New Issue
Block a user