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
pub use mailpot::{models::*, *};
use warp::Filter;
#[tokio::main]
async fn main() {
let config_path = std::env::args()
.nth(1)
.expect("Expected configuration file path as first argument.");
let conf = Configuration::from_file(config_path).unwrap();
let conf1 = conf.clone();
let policy = warp::path!("lists" / i64 / "policy").map(move |list_pk| {
let db = Connection::open_db(conf1.clone()).unwrap();
db.list_post_policy(list_pk)
.ok()
.map(|l| warp::reply::json(&l.unwrap()))
.unwrap()
});
let conf2 = conf.clone();
let lists = warp::path!("lists").map(move || {
let db = Connection::open_db(conf2.clone()).unwrap();
let lists = db.lists().unwrap();
warp::reply::json(&lists)
});
let conf3 = conf.clone();
let lists_num = warp::path!("lists" / i64).map(move |list_pk| {
let db = Connection::open_db(conf3.clone()).unwrap();
let list = db.list(list_pk).unwrap();
warp::reply::json(&list)
});
let conf4 = conf.clone();
let lists_subscriptions = warp::path!("lists" / i64 / "subscriptions").map(move |list_pk| {
let db = Connection::open_db(conf4.clone()).unwrap();
db.list_subscriptions(list_pk)
.ok()
.map(|l| warp::reply::json(&l))
.unwrap()
});
let lists_owners = warp::path!("lists" / i64 / "owners").map(move |list_pk| {
let db = Connection::open_db(conf.clone()).unwrap();
db.list_owners(list_pk)
.ok()
.map(|l| warp::reply::json(&l))
.unwrap()
});
let lists_owner_add =
warp::post().and(warp::path!("lists" / i64 / "owners" / "add").map(|_list_pk| "todo"));
let routes = warp::get().and(
lists
.or(policy)
.or(lists_num)
.or(lists_subscriptions)
.or(lists_owners)
.or(lists_owner_add),
);
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}