use crate::model::frequency::Frequency; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, Clone)] pub struct Payments { pub page: Option, pub name: Option, pub cost: Option, pub frequency: Option, pub highlight: Option, pub user: Option, pub category: Option, pub start_date: Option, pub end_date: Option, } 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)), }; if let Some(Frequency::Monthly) = q.frequency { params.push("frequency=Monthly".to_string()) }; if let Some(id) = q.highlight { params.push(format!("highlight={}", id)) }; if let Some(str) = q.name { if !str.is_empty() { params.push(format!("name={}", str)) } }; if let Some(str) = q.cost { if !str.is_empty() { params.push(format!("cost={}", str)) } }; if let Some(id) = q.user { params.push(format!("user={}", id)) }; if let Some(id) = q.category { params.push(format!("category={}", id)) }; if let Some(str) = q.start_date { if !str.is_empty() { params.push(format!("start_date={}", str)) } }; if let Some(str) = q.end_date { if !str.is_empty() { params.push(format!("end_date={}", str)) } }; if params.is_empty() { "".to_string() } else { format!("?{}", params.join("&")) } } #[derive(Deserialize, Serialize, Clone)] pub struct Incomes { pub page: Option, pub highlight: Option, } #[derive(Deserialize, Serialize, Clone)] pub struct Categories { pub highlight: Option, } #[derive(Deserialize, Serialize)] pub struct PaymentCategory { pub payment_name: String, }