From 99466c6ceb848cf8147645f25deea89804b7b279 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 10 Oct 2021 21:21:06 +0200 Subject: Filter payments by start and end date --- src/queries.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/queries.rs') diff --git a/src/queries.rs b/src/queries.rs index f10c7a1..db098e7 100644 --- a/src/queries.rs +++ b/src/queries.rs @@ -10,6 +10,8 @@ pub struct Payments { pub highlight: Option, pub user: Option, pub category: Option, + pub start_date: Option, + pub end_date: Option, } pub fn payments_url(q: Payments) -> String { @@ -33,12 +35,20 @@ pub fn payments_url(q: Payments) -> String { }; match q.name { - Some(str) => params.push(format!("name={}", str)), + Some(str) => { + if !str.is_empty() { + params.push(format!("name={}", str)) + } + } _ => (), }; match q.cost { - Some(n) => params.push(format!("cost={}", n)), + Some(str) => { + if !str.is_empty() { + params.push(format!("cost={}", str)) + } + } _ => (), }; @@ -52,6 +62,24 @@ pub fn payments_url(q: Payments) -> String { _ => (), }; + match q.start_date { + Some(str) => { + if !str.is_empty() { + params.push(format!("start_date={}", str)) + } + } + _ => (), + }; + + match q.end_date { + Some(str) => { + if !str.is_empty() { + params.push(format!("end_date={}", str)) + } + } + _ => (), + }; + if params.is_empty() { "".to_string() } else { -- cgit v1.2.3