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