diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/action.rs | 1 | ||||
-rw-r--r-- | src/model/category.rs | 20 | ||||
-rw-r--r-- | src/model/config.rs | 8 | ||||
-rw-r--r-- | src/model/frequency.rs | 31 | ||||
-rw-r--r-- | src/model/income.rs | 40 | ||||
-rw-r--r-- | src/model/job.rs | 5 | ||||
-rw-r--r-- | src/model/login.rs | 5 | ||||
-rw-r--r-- | src/model/mod.rs | 9 | ||||
-rw-r--r-- | src/model/payment.rs | 53 | ||||
-rw-r--r-- | src/model/report.rs | 16 | ||||
-rw-r--r-- | src/model/user.rs | 8 |
11 files changed, 196 insertions, 0 deletions
diff --git a/src/model/action.rs b/src/model/action.rs new file mode 100644 index 0000000..a77543a --- /dev/null +++ b/src/model/action.rs @@ -0,0 +1 @@ +use serde::Serialize; diff --git a/src/model/category.rs b/src/model/category.rs new file mode 100644 index 0000000..de08dea --- /dev/null +++ b/src/model/category.rs @@ -0,0 +1,20 @@ +use serde::Serialize; + +#[derive(sqlx::FromRow, Serialize)] +pub struct Category { + pub id: i64, + pub name: String, + pub color: String, +} + +#[derive(Debug)] +pub struct Create { + pub name: String, + pub color: String, +} + +#[derive(Debug)] +pub struct Update { + pub name: String, + pub color: String, +} diff --git a/src/model/config.rs b/src/model/config.rs new file mode 100644 index 0000000..8d304e5 --- /dev/null +++ b/src/model/config.rs @@ -0,0 +1,8 @@ +use serde::Deserialize; + +#[derive(Clone, Deserialize)] +pub struct Config { + pub secure_cookies: bool, + pub mock_mails: bool, + pub sendmail_path: String, +} diff --git a/src/model/frequency.rs b/src/model/frequency.rs new file mode 100644 index 0000000..bb83e27 --- /dev/null +++ b/src/model/frequency.rs @@ -0,0 +1,31 @@ +use serde::{Deserialize, Serialize}; +use std::{fmt, str}; + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, sqlx::Type)] +pub enum Frequency { + Punctual, + Monthly, +} + +impl fmt::Display for Frequency { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Frequency::Punctual => write!(f, "Punctual"), + Frequency::Monthly => write!(f, "Monthly"), + } + } +} + +pub struct ParseFrequencyError; + +impl str::FromStr for Frequency { + type Err = ParseFrequencyError; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "Punctual" => Ok(Frequency::Punctual), + "Monthly" => Ok(Frequency::Monthly), + _ => Err(ParseFrequencyError {}), + } + } +} diff --git a/src/model/income.rs b/src/model/income.rs new file mode 100644 index 0000000..7bc888f --- /dev/null +++ b/src/model/income.rs @@ -0,0 +1,40 @@ +use serde::Serialize; + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct Stat { + pub date: String, + pub amount: i64, +} + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct Table { + pub id: i64, + pub date: String, + pub user: String, + pub amount: i64, +} + +#[derive(Debug, Clone, sqlx::FromRow, Serialize)] +pub struct Form { + pub id: i64, + pub amount: i64, + pub user_id: i64, + pub month: i64, + pub year: i64, +} + +#[derive(Debug)] +pub struct Create { + pub user_id: i64, + pub amount: i64, + pub month: u32, + pub year: i32, +} + +#[derive(Debug)] +pub struct Update { + pub user_id: i64, + pub amount: i64, + pub month: u32, + pub year: i32, +} diff --git a/src/model/job.rs b/src/model/job.rs new file mode 100644 index 0000000..74151ae --- /dev/null +++ b/src/model/job.rs @@ -0,0 +1,5 @@ +#[derive(Debug, sqlx::Type)] +pub enum Job { + MonthlyPayment, + WeeklyReport, +} diff --git a/src/model/login.rs b/src/model/login.rs new file mode 100644 index 0000000..c7a10ba --- /dev/null +++ b/src/model/login.rs @@ -0,0 +1,5 @@ +#[derive(Debug)] +pub struct Login { + pub email: String, + pub password: String, +} diff --git a/src/model/mod.rs b/src/model/mod.rs new file mode 100644 index 0000000..fb07721 --- /dev/null +++ b/src/model/mod.rs @@ -0,0 +1,9 @@ +pub mod category; +pub mod config; +pub mod frequency; +pub mod income; +pub mod job; +pub mod login; +pub mod payment; +pub mod report; +pub mod user; diff --git a/src/model/payment.rs b/src/model/payment.rs new file mode 100644 index 0000000..5ce6bb9 --- /dev/null +++ b/src/model/payment.rs @@ -0,0 +1,53 @@ +use chrono::NaiveDate; +use serde::Serialize; + +use crate::model::frequency::Frequency; + +#[derive(Debug, sqlx::FromRow, Serialize)] +pub struct Table { + pub id: i64, + pub name: String, + pub cost: i64, + pub user: String, + pub category_name: String, + pub category_color: String, + pub date: String, + pub frequency: Frequency, +} + +#[derive(Debug, sqlx::FromRow, Serialize)] +pub struct Form { + pub id: i64, + pub name: String, + pub cost: i64, + pub user_id: i64, + pub category_id: i64, + pub date: String, + pub frequency: Frequency, +} + +#[derive(Debug, sqlx::FromRow, Serialize)] +pub struct Stat { + pub start_date: String, + pub cost: i64, + pub category_id: i64, +} + +#[derive(Debug)] +pub struct Create { + pub name: String, + pub cost: i64, + pub user_id: i64, + pub category_id: i64, + pub date: NaiveDate, + pub frequency: Frequency, +} + +#[derive(Debug)] +pub struct Update { + pub name: String, + pub cost: i64, + pub user_id: i64, + pub category_id: i64, + pub date: NaiveDate, +} diff --git a/src/model/report.rs b/src/model/report.rs new file mode 100644 index 0000000..4858402 --- /dev/null +++ b/src/model/report.rs @@ -0,0 +1,16 @@ +use serde::Serialize; + +#[derive(Debug, sqlx::FromRow, Serialize)] +pub struct Report { + pub date: String, + pub name: String, + pub amount: i64, + pub action: Action, +} + +#[derive(Debug, PartialEq, Serialize, sqlx::Type)] +pub enum Action { + Created, + Updated, + Deleted, +} diff --git a/src/model/user.rs b/src/model/user.rs new file mode 100644 index 0000000..e8a61bf --- /dev/null +++ b/src/model/user.rs @@ -0,0 +1,8 @@ +use serde::Serialize; + +#[derive(Debug, sqlx::FromRow, Clone, Serialize)] +pub struct User { + pub id: i64, + pub name: String, + pub email: String, +} |