tetrio_api/http/parameters/
value_bound_query.rs1use serde::{Deserialize, Serialize};
2
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct Prisecter {
8 pub pri: f64,
9 pub sec: f64,
10 pub ter: f64,
11}
12
13impl ToString for Prisecter {
14 fn to_string(&self) -> String {
15 return format!("{}:{}:{}", self.pri, self.sec, self.ter)
16 }
17}
18
19
20pub enum ValueBoundQuery {
21 After {
22 after: Prisecter,
23 limit: Option<i64>,
24 country: Option<String>,
25 },
26 Before {
27 before: Prisecter,
28 limit: Option<i64>,
29 country: Option<String>,
30 },
31 NotBound {
32 limit: Option<i64>,
33 country: Option<String>,
34 },
35 None,
36}
37
38impl ValueBoundQuery {
39 pub fn as_query_params(self) -> Vec<[String; 2]> {
40 let mut result = vec![];
41 match self {
42 ValueBoundQuery::After {
43 after,
44 limit,
45 country,
46 ..
47 } => {
48 result.push(["after".to_string(), after.to_string()]);
49 if let Some(limit) = limit {
50 result.push(["limit".to_string(), limit.to_string()]);
51 };
52
53 if let Some(country) = country {
54 result.push(["country".to_string(), country.to_string()]);
55 };
56 }
57 ValueBoundQuery::Before {
58 before,
59 limit,
60 country,
61 ..
62 } => {
63 result.push(["before".to_string(), before.to_string()]);
64 if let Some(limit) = limit {
65 result.push(["limit".to_string(), limit.to_string()]);
66 };
67
68 if let Some(country) = country {
69 result.push(["country".to_string(), country.to_string()]);
70 };
71 }
72 ValueBoundQuery::NotBound { limit, country } => {
73 if let Some(limit) = limit {
74 result.push(["limit".to_string(), limit.to_string()]);
75 };
76
77 if let Some(country) = country {
78 result.push(["country".to_string(), country.to_string()]);
79 };
80 }
81 ValueBoundQuery::None => {},
82 };
83
84 return result;
85 }
86}