1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use serde::{Deserialize, Serialize};
use crate::i18n::I18n;
use crate::image::Image;
use crate::pagination::Page;
use crate::params;
use crate::tag::Tag;
#[derive(Debug, Serialize, Deserialize)]
pub struct Project {
pub absolute_url: String,
pub amount_raised: u64,
pub country: String,
pub currency: String,
pub date_end: Option<String>,
pub date_start: Option<String>,
pub finished: bool,
pub goal: u64,
pub id: u64,
pub lang: String,
pub name: I18n,
pub nb_products_sold: u64,
pub slug: String,
pub subtitle: I18n,
#[serde(alias = "type")]
pub kind: String,
pub main_image: Option<Image>,
pub main_tag: Option<Tag>,
pub owner: Option<User>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Projects {
pub projects: Vec<Project>,
pub meta: Page,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
pub absolute_url: String,
pub first_name: String,
pub id: u64,
pub last_name: String,
pub name: String,
pub screenname: String,
pub username: String,
}
pub type Params = params::Params;
impl Params {
pub fn with_langs(self, langs: Vec<String>) -> Params {
self.add_query("langs", langs.join(","))
}
pub fn with_countries(self, countries: Vec<String>) -> Params {
self.add_query("countries", countries.join(","))
}
pub fn with_partners(self, partners: Vec<String>) -> Params {
self.add_query("partners", partners.join(","))
}
pub fn with_status(self, status: impl Into<String>) -> Params {
self.add_query("status", status)
}
pub fn with_selected_ids(self, ids: Vec<u64>) -> Params {
let selected: Vec<String> = ids.iter().map(|i| i.to_string()).collect();
self.add_query("selected_ids", selected.join(","))
}
pub fn with_term(self, term: impl Into<String>) -> Params {
self.add_query(term, "")
}
pub fn with_query_sort(self, sort: String) -> Params {
self.add_query("sort", sort)
}
pub fn with_tag_id(self, id: u64) -> Params {
self.add_query("tag_id", id.to_string())
}
pub fn with_owner_id(self, id: u64) -> Params {
self.add_query("owner_id", id.to_string())
}
pub fn with_city_id(self, id: u64) -> Params {
self.add_query("city_id", id.to_string())
}
pub fn with_region_id(self, id: u64) -> Params {
self.add_query("region_id", id.to_string())
}
}
#[cfg(test)]
mod tests {
#[test]
fn with_selected_ids() {
use super::Params;
let p = Params::new().with_selected_ids(vec![42, 1337]);
assert_eq!(p.to_string(), "?q=selected_ids:42,1337");
}
}