summaryrefslogtreecommitdiff
path: root/backend/importers/actualbudget/src/models/budgeting_app
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2024-10-16 12:51:21 +0100
committerJoe Carstairs <me@joeac.net>2024-10-16 12:51:21 +0100
commit27b95c9186bd45edd4c982a7cc89cf69cf2c5d46 (patch)
treebf104ff9d64e601bfec5516eb51ef298f3095e9b /backend/importers/actualbudget/src/models/budgeting_app
parent76974785294089965efc3f55b2a08d4089029c52 (diff)
All backend stuff lives in backend folder
Diffstat (limited to 'backend/importers/actualbudget/src/models/budgeting_app')
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/DateTimeUtc.rs57
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/account.rs8
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/budget_update.rs10
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/category.rs4
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/category_transfer.rs7
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/date_time_utc.rs20
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/mod.rs7
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/transaction.rs11
-rw-r--r--backend/importers/actualbudget/src/models/budgeting_app/transaction_categorisation.rs7
9 files changed, 131 insertions, 0 deletions
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/DateTimeUtc.rs b/backend/importers/actualbudget/src/models/budgeting_app/DateTimeUtc.rs
new file mode 100644
index 0000000..e44fa8c
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/DateTimeUtc.rs
@@ -0,0 +1,57 @@
+use chrono::{DateTime, Datelike, Utc};
+use diesel::{
+ deserialize::{FromSql, FromSqlRow},
+ expression::AsExpression,
+ serialize::ToSql,
+ sql_types::Text,
+ sqlite::Sqlite,
+};
+use serde::{Deserialize, Serialize};
+
+#[derive(
+ Eq,
+ PartialEq,
+ Ord,
+ PartialOrd,
+ Serialize,
+ Deserialize,
+ Copy,
+ Clone,
+ Debug,
+ AsExpression,
+ FromSqlRow,
+)]
+#[diesel(sql_type=Text)]
+pub struct DateTimeUtc(DateTime<Utc>);
+
+impl DateTimeUtc {
+ pub fn day_diff(&self, other: &DateTimeUtc) -> u32 {
+ self.0
+ .num_days_from_ce()
+ .abs_diff(other.0.num_days_from_ce())
+ }
+
+ pub fn new(date_time_utc: DateTime<Utc>) -> Self {
+ Self(date_time_utc)
+ }
+}
+
+impl ToSql<Text, Sqlite> for DateTimeUtc {
+ fn to_sql<'b>(
+ &'b self,
+ out: &mut diesel::serialize::Output<'b, '_, Sqlite>,
+ ) -> diesel::serialize::Result {
+ out.set_value((*self).0.to_rfc3339());
+ Ok(diesel::serialize::IsNull::No)
+ }
+}
+
+impl FromSql<Text, Sqlite> for DateTimeUtc {
+ fn from_sql(
+ bytes: <Sqlite as diesel::backend::Backend>::RawValue<'_>,
+ ) -> diesel::deserialize::Result<Self> {
+ let str: String = FromSql::<Text, Sqlite>::from_sql(bytes)?;
+ let date_time = str.as_str().parse::<DateTime<Utc>>()?;
+ Ok(DateTimeUtc(date_time))
+ }
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/account.rs b/backend/importers/actualbudget/src/models/budgeting_app/account.rs
new file mode 100644
index 0000000..165b55c
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/account.rs
@@ -0,0 +1,8 @@
+use super::date_time_utc::DateTimeUtc;
+
+pub struct Account {
+ pub id: i32,
+ pub name: String,
+ pub opening_balance: i32,
+ pub opening_date: DateTimeUtc,
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/budget_update.rs b/backend/importers/actualbudget/src/models/budgeting_app/budget_update.rs
new file mode 100644
index 0000000..9958446
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/budget_update.rs
@@ -0,0 +1,10 @@
+use super::date_time_utc::DateTimeUtc;
+
+#[derive(Clone)]
+pub struct BudgetUpdate {
+ pub id: i32,
+ pub category_id: i32,
+ pub date: DateTimeUtc,
+ pub new_budget: i32,
+ pub new_period: i32,
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/category.rs b/backend/importers/actualbudget/src/models/budgeting_app/category.rs
new file mode 100644
index 0000000..3f51dfd
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/category.rs
@@ -0,0 +1,4 @@
+pub struct Category {
+ pub id: i32,
+ pub name: String,
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/category_transfer.rs b/backend/importers/actualbudget/src/models/budgeting_app/category_transfer.rs
new file mode 100644
index 0000000..0097429
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/category_transfer.rs
@@ -0,0 +1,7 @@
+pub struct CategoryTransfer {
+ pub id: i32,
+ pub description: String,
+ pub quantity: i32,
+ pub from_category_id: i32,
+ pub to_category_id: i32,
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/date_time_utc.rs b/backend/importers/actualbudget/src/models/budgeting_app/date_time_utc.rs
new file mode 100644
index 0000000..69cdfe2
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/date_time_utc.rs
@@ -0,0 +1,20 @@
+use std::{fmt::Display, str::FromStr};
+
+use chrono::{DateTime, Utc};
+
+#[derive(Clone)]
+pub struct DateTimeUtc(DateTime<Utc>);
+
+impl DateTimeUtc {
+ pub fn new(date: &str) -> Self {
+ let mut date_time = String::from(date);
+ date_time.push_str("T00:00:00.000Z");
+ Self(DateTime::<Utc>::from_str(&date_time).unwrap())
+ }
+}
+
+impl Display for DateTimeUtc {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.0.fmt(f)
+ }
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/mod.rs b/backend/importers/actualbudget/src/models/budgeting_app/mod.rs
new file mode 100644
index 0000000..bca0f99
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/mod.rs
@@ -0,0 +1,7 @@
+pub mod account;
+pub mod budget_update;
+pub mod category;
+pub mod category_transfer;
+pub mod date_time_utc;
+pub mod transaction;
+pub mod transaction_categorisation;
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/transaction.rs b/backend/importers/actualbudget/src/models/budgeting_app/transaction.rs
new file mode 100644
index 0000000..e679e1e
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/transaction.rs
@@ -0,0 +1,11 @@
+use super::date_time_utc::DateTimeUtc;
+
+#[derive(Clone)]
+pub struct Transaction {
+ pub id: i32,
+ pub description: String,
+ pub payee: String,
+ pub quantity: i32,
+ pub date: DateTimeUtc,
+ pub account_id: i32,
+}
diff --git a/backend/importers/actualbudget/src/models/budgeting_app/transaction_categorisation.rs b/backend/importers/actualbudget/src/models/budgeting_app/transaction_categorisation.rs
new file mode 100644
index 0000000..ca7e7f5
--- /dev/null
+++ b/backend/importers/actualbudget/src/models/budgeting_app/transaction_categorisation.rs
@@ -0,0 +1,7 @@
+pub struct TransactionCategorisation {
+ pub id: i32,
+ pub description: String,
+ pub quantity: i32,
+ pub transaction_id: i32,
+ pub category_id: i32,
+}