aboutsummaryrefslogtreecommitdiff
path: root/src/queries.rs
diff options
context:
space:
mode:
authorJoris2021-01-03 13:40:40 +0100
committerJoris2021-01-03 13:54:20 +0100
commit11052951b74b9ad4b6a9412ae490086235f9154b (patch)
tree64526ac926c1bf470ea113f6cac8a33158684e8d /src/queries.rs
parent371449b0e312a03162b78797b83dee9d81706669 (diff)
downloadbudget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.gz
budget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.bz2
budget-11052951b74b9ad4b6a9412ae490086235f9154b.zip
Rewrite in Rust
Diffstat (limited to 'src/queries.rs')
-rw-r--r--src/queries.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/queries.rs b/src/queries.rs
new file mode 100644
index 0000000..a7ba28c
--- /dev/null
+++ b/src/queries.rs
@@ -0,0 +1,62 @@
+use crate::model::frequency::Frequency;
+use serde::{Deserialize, Serialize};
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct Payments {
+ pub page: Option<i64>,
+ pub search: Option<String>,
+ pub frequency: Option<Frequency>,
+ pub highlight: Option<i64>,
+}
+
+pub fn payments_url(q: Payments) -> String {
+ let mut params = Vec::new();
+
+ match q.page {
+ None | Some(1) => (),
+ Some(p) => params.push(format!("page={}", p)),
+ };
+
+ match q.search {
+ Some(s) => {
+ if !s.is_empty() {
+ params.push(format!("search={}", s));
+ }
+ }
+ _ => (),
+ };
+
+ match q.frequency {
+ Some(Frequency::Monthly) => {
+ params.push("frequency=Monthly".to_string())
+ }
+ _ => (),
+ };
+
+ match q.highlight {
+ Some(id) => params.push(format!("highlight={}", id)),
+ _ => (),
+ };
+
+ if params.is_empty() {
+ "".to_string()
+ } else {
+ format!("?{}", params.join("&"))
+ }
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct Incomes {
+ pub page: Option<i64>,
+ pub highlight: Option<i64>,
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct Categories {
+ pub highlight: Option<i64>,
+}
+
+#[derive(Deserialize, Serialize)]
+pub struct PaymentCategory {
+ pub payment_name: String,
+}