Still working on this shit...
This commit is contained in:
1 parent
89597dcac2
commit
801abed9a4
6 files changed
+65
-15
No files matched your search
+35
-1
@@ -1,10 +1,35 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::db::securities::{NewSecurity, SecurityType};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct CreateNewSecurity {
|
||||
pub security_type: String,
|
||||
pub symbol: String,
|
||||
pub name: String,
|
||||
pub age: i64,
|
||||
}
|
||||
|
||||
impl CreateNewSecurity {
|
||||
fn get_security_type(&self) -> Option<SecurityType>{
|
||||
SecurityType::from_string(self.security_type.clone())
|
||||
}
|
||||
pub fn to_create_new_security(&self) -> Option<NewSecurity> {
|
||||
self.get_security_type()
|
||||
.map(|security_type|
|
||||
NewSecurity {
|
||||
security_type,
|
||||
symbol: self.symbol.clone(),
|
||||
name: self.name.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
fn validate_event(&self) -> Result<(), String>{
|
||||
if SecurityType::from_string(self.security_type.clone()).is_none(){
|
||||
Err(format!("Invalid SecurityType \"{}\".", self.security_type))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
@@ -17,4 +42,13 @@ pub struct CreateNewUser {
|
||||
pub enum Event {
|
||||
CreateNewSecurity(CreateNewSecurity),
|
||||
CreateNewUser(CreateNewUser),
|
||||
}
|
||||
|
||||
impl Event {
|
||||
pub fn validate_event(&self) -> Result<(), String>{
|
||||
match self {
|
||||
Event::CreateNewSecurity(event) => event.validate_event(),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user