diff options
Diffstat (limited to 'src/model/report.rs')
-rw-r--r-- | src/model/report.rs | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/src/model/report.rs b/src/model/report.rs deleted file mode 100644 index e944745..0000000 --- a/src/model/report.rs +++ /dev/null @@ -1,40 +0,0 @@ -use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ValueRef}; -use std::fmt; - -#[derive(Debug, serde::Serialize)] -pub struct Report { - pub date: String, - pub name: String, - pub amount: i64, - pub action: Action, -} - -#[derive(Debug, PartialEq, serde::Serialize)] -pub enum Action { - Created, - Updated, - Deleted, -} - -impl fmt::Display for Action { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self) - } -} - -impl FromSql for Action { - fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> { - match value { - ValueRef::Text(text) => match std::str::from_utf8(text) { - Ok("Created") => Ok(Action::Created), - Ok("Updated") => Ok(Action::Updated), - Ok("Deleted") => Ok(Action::Deleted), - Ok(str) => Err(FromSqlError::Other( - format!("Unknown action: {str}").into(), - )), - Err(err) => Err(FromSqlError::Other(err.into())), - }, - _ => Err(FromSqlError::InvalidType), - } - } -} |