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
use ;
use serde_json;
use ArtifactData;
use ARTIFACTS;
lazy_static!
/// `GetArtifacts` API Handler
;
// helper methods for UpdateArtifacts
//fn invalid_params(desc: &str) -> Error {
// Error {
// code: ErrorCode::InvalidParams,
// message: desc.to_string(),
// data: None,
// }
//}
//fn get_artifact<'a>(artifacts: &'a mut Vec<ArtifactData>, id: u64)
// -> Result<&'a mut ArtifactData, String> {
// match artifacts.iter_mut().filter(|p| p.id == id).next() {
// Some(a) => Ok(a),
// None => {
// println!("- id not found: {}", id);
// Err(format!("Artifact {} not found", id))
// },
// }
//}
//fn parse_error(desc: &str) -> Error {
// Error {
// code: ErrorCode::ParseError,
// message: desc.to_string(),
// data: None,
// }
//}
// /// UpdateArtifacts Handler
//struct UpdateArtifacts;
//impl SyncMethodCommand for GetArtifacts {
// fn execute(&self, params: Params) -> Result<Value, Error> {
// println!("* UpdateArtifacts");
// let new = match params {
// Map(dict) => match dict.get("artifacts") {
// Some(value) => match serde_json::from_value::Vec<Artifact>(value) {
// Ok(a) => a,
// Err(e) => return parse_error(format!("{}", e)),
// }
// None => return invalid_params("missing 'artifacts' param"),
// }
// _ => return invalid_params("params must have 'artifacts' key"),
// };
// let id = match parse_id(req) {
// Ok(id) => id,
// Err(e) => {
// res.set(StatusCode::NotFound);
// return res.send(e);
// },
// };
// let mut locked = ARTIFACTS.lock().unwrap();
// let artifact = match get_artifact(locked.as_mut(), id) {
// Ok(a) => a,
// Err(e) => {
// res.set(StatusCode::NotFound);
// return res.send(e);
// },
// };
// let new = match req.json_as::<Artifact>() {
// Ok(a) => a,
// Err(e) => {
// res.set(StatusCode::BadRequest);
// return res.send(format!("{}", e));
// },
// };
// if new.id != id {
// res.set(StatusCode::BadRequest);
// return res.send("cannot change artifact's id");
// }
// if new == *artifact {
// res.set(StatusCode::NotModified);
// return res.send("not modified");
// }
// *artifact = new;
// let data = json::as_pretty_json(artifact);
// let str_data = format!("{}", data);
// println!("* PUT /artifacts/{} success", id);
// config_json_res(&mut res);
// res.send(str_data)
// }
//}