mirror of
https://github.com/hannobraun/Fornjot
synced 2025-10-24 00:38:20 +00:00
Prepare for more types of validation events
This commit is contained in:
parent
10aeba2696
commit
42d35559c8
@ -11,7 +11,7 @@ use crate::objects::{Object, Objects, WithHandle};
|
|||||||
pub use self::{
|
pub use self::{
|
||||||
objects::{InsertObject, Operation},
|
objects::{InsertObject, Operation},
|
||||||
service::{Service, State},
|
service::{Service, State},
|
||||||
validation::{Validation, ValidationCommand, ValidationFailed},
|
validation::{Validation, ValidationCommand, ValidationEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The kernel services
|
/// The kernel services
|
||||||
|
|||||||
@ -36,7 +36,7 @@ impl Drop for Validation {
|
|||||||
|
|
||||||
impl State for Validation {
|
impl State for Validation {
|
||||||
type Command = ValidationCommand;
|
type Command = ValidationCommand;
|
||||||
type Event = ValidationFailed;
|
type Event = ValidationEvent;
|
||||||
|
|
||||||
fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>) {
|
fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>) {
|
||||||
let ValidationCommand::ValidateObject { object } = command;
|
let ValidationCommand::ValidateObject { object } = command;
|
||||||
@ -45,7 +45,7 @@ impl State for Validation {
|
|||||||
object.validate(&mut errors);
|
object.validate(&mut errors);
|
||||||
|
|
||||||
for err in errors {
|
for err in errors {
|
||||||
events.push(ValidationFailed {
|
events.push(ValidationEvent::ValidationFailed {
|
||||||
object: object.clone(),
|
object: object.clone(),
|
||||||
err,
|
err,
|
||||||
});
|
});
|
||||||
@ -53,7 +53,11 @@ impl State for Validation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn evolve(&mut self, event: &Self::Event) {
|
fn evolve(&mut self, event: &Self::Event) {
|
||||||
self.errors.insert(event.object.id(), event.err.clone());
|
match event {
|
||||||
|
ValidationEvent::ValidationFailed { object, err } => {
|
||||||
|
self.errors.insert(object.id(), err.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +72,13 @@ pub enum ValidationCommand {
|
|||||||
|
|
||||||
/// The event produced by the validation service
|
/// The event produced by the validation service
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ValidationFailed {
|
pub enum ValidationEvent {
|
||||||
/// The object for which validation failed
|
/// Validation of an object failed
|
||||||
pub object: Object<BehindHandle>,
|
ValidationFailed {
|
||||||
|
/// The object for which validation failed
|
||||||
|
object: Object<BehindHandle>,
|
||||||
|
|
||||||
/// The validation error
|
/// The validation error
|
||||||
pub err: ValidationError,
|
err: ValidationError,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user