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
+13
-4
@@ -1,4 +1,4 @@
|
||||
use rusqlite::{params, Connection, Result, Row, ToSql, Transaction};
|
||||
use rusqlite::{Connection, params, Result, Row, ToSql, Transaction};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::db::_external_id::{Id, SecurityId};
|
||||
@@ -11,7 +11,7 @@ pub enum SecurityType {
|
||||
}
|
||||
|
||||
impl SecurityType {
|
||||
fn from_string(s: String) -> SecurityType {
|
||||
fn from_string_unsafe(s: String) -> SecurityType {
|
||||
if s == "currency".to_string() {
|
||||
return SecurityType::Currency;
|
||||
}
|
||||
@@ -20,6 +20,15 @@ impl SecurityType {
|
||||
}
|
||||
panic!("Impossible to convert string {} to SecurityType.", s);
|
||||
}
|
||||
pub fn from_string(s: String) -> Option<SecurityType> {
|
||||
if s == "currency".to_string() {
|
||||
Some(SecurityType::Currency)
|
||||
} else if s == "bond".to_string() {
|
||||
Some(SecurityType::Bond)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql for SecurityType {
|
||||
@@ -49,7 +58,7 @@ impl Security {
|
||||
pub fn from_row(row: &Row) -> Result<Security> {
|
||||
Ok(Security {
|
||||
id: row.get("sec_id")?,
|
||||
security_type: SecurityType::from_string(row.get("sec_security_type")?),
|
||||
security_type: SecurityType::from_string_unsafe(row.get("sec_security_type")?),
|
||||
symbol: row.get("sec_symbol")?,
|
||||
})
|
||||
}
|
||||
@@ -97,7 +106,7 @@ pub fn list_securities(conn: &Connection) -> CustomResult<Vec<Security>> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_securities {
|
||||
use rusqlite::{params, Connection};
|
||||
use rusqlite::{Connection, params};
|
||||
|
||||
use crate::db::_test_utils::*;
|
||||
use crate::db::users::User;
|
||||
|
||||
Reference in new issue
Block a user