mirror of
https://github.com/hannobraun/Fornjot
synced 2025-10-25 09:18:10 +00:00
Merge pull request #2261 from hannobraun/layer
Add `ValidateObject` command
This commit is contained in:
commit
315bf19b68
@ -5,7 +5,7 @@ use crate::{
|
||||
validation::Validation,
|
||||
};
|
||||
|
||||
use super::{Command, Event, Layer};
|
||||
use super::{validation::ValidateObject, Command, Event, Layer};
|
||||
|
||||
impl Layer<Objects> {
|
||||
/// Insert an object into the stores
|
||||
@ -20,15 +20,15 @@ impl Layer<Objects> {
|
||||
self.process(InsertObject { object }, &mut events);
|
||||
|
||||
for event in events {
|
||||
let event = ValidateObject {
|
||||
object: event.object.into(),
|
||||
};
|
||||
validation.process(event, &mut Vec::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert an object into the stores
|
||||
///
|
||||
/// This struct serves as both event and command for `Layer<Objects>`, as well
|
||||
/// as a command for `Layer<Validation>`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct InsertObject {
|
||||
/// The object to insert
|
||||
|
||||
@ -5,7 +5,7 @@ use crate::{
|
||||
validation::{Validation, ValidationError, ValidationErrors},
|
||||
};
|
||||
|
||||
use super::{objects::InsertObject, Command, Event, Layer};
|
||||
use super::{Command, Event, Layer};
|
||||
|
||||
impl Layer<Validation> {
|
||||
/// Take all errors stored in the validation layer
|
||||
@ -14,19 +14,23 @@ impl Layer<Validation> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<Validation> for InsertObject {
|
||||
/// Validate an object
|
||||
pub struct ValidateObject {
|
||||
/// The object to validate
|
||||
pub object: AnyObject<Stored>,
|
||||
}
|
||||
|
||||
impl Command<Validation> for ValidateObject {
|
||||
type Result = ();
|
||||
type Event = ValidationFailed;
|
||||
|
||||
fn decide(self, state: &Validation, events: &mut Vec<Self::Event>) {
|
||||
let mut errors = Vec::new();
|
||||
|
||||
let object: AnyObject<Stored> = self.object.into();
|
||||
object.validate(&state.config, &mut errors);
|
||||
self.object.validate(&state.config, &mut errors);
|
||||
|
||||
for err in errors {
|
||||
events.push(ValidationFailed {
|
||||
object: object.clone(),
|
||||
object: self.object.clone(),
|
||||
err,
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user