-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathexport.rs
44 lines (39 loc) · 1.22 KB
/
export.rs
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
use std::collections::HashMap;
use rocket::http::Status;
use rocket::State;
use rocket_contrib::json::Json;
use rocket_okapi::openapi;
use aw_models::BucketsExport;
use crate::endpoints::{HttpErrorJson, ServerState};
#[openapi]
#[get("/")]
pub fn buckets_export(state: State<ServerState>) -> Result<Json<BucketsExport>, HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
let mut export = BucketsExport {
buckets: HashMap::new(),
};
let mut buckets = match datastore.get_buckets() {
Ok(buckets) => buckets,
Err(err) => return Err(err.into()),
};
for (bid, mut bucket) in buckets.drain() {
bucket.events = Some(match datastore.get_events(&bid, None, None, None) {
Ok(events) => events,
Err(err) => return Err(err.into()),
});
export.buckets.insert(bid, bucket);
}
/*
Ok(Response::build()
.status(Status::Ok)
.header(Header::new(
"Content-Disposition",
"attachment; filename=aw-buckets-export.json",
))
.sized_body(Cursor::new(
serde_json::to_string(&export).expect("Failed to serialize"),
))
.finalize())
*/
Ok(Json(export))
}