Technical test for a job interview.
1#![feature(proc_macro_hygiene, decl_macro)]
2
3#[macro_use] extern crate rocket;
4
5mod utils;
6mod download;
7
8#[get("/weather?<city>&<state>&<country>&<unit>")]
9fn weather(city: String,
10 state: Option<String>,
11 country: Option<String>,
12 unit: Option<String>) -> String
13{
14 let temp_unit = match unit {
15 Some(s) if s == "c" || s == "C" => utils::Temp::C,
16 Some(s) if s == "f" || s == "F" => utils::Temp::C,
17 _ => utils::Temp::K,
18 };
19 download::call_api(None,
20 utils::Query::Weather,
21 String::from("960c6bd08da0acfb2debc737573930c6"),
22 city,
23 state,
24 country,
25 temp_unit
26 ).unwrap()
27}
28
29#[get("/forecast?<city>&<state>&<country>&<unit>")]
30fn forecast(city: String,
31 state: Option<String>,
32 country: Option<String>,
33 unit: Option<String>) -> String
34{
35 let temp_unit = match unit {
36 Some(s) if s == "c" || s == "C" => utils::Temp::C,
37 Some(s) if s == "f" || s == "F" => utils::Temp::C,
38 _ => utils::Temp::K,
39 };
40 download::call_api(None,
41 utils::Query::Forecast,
42 String::from("960c6bd08da0acfb2debc737573930c6"),
43 city,
44 state,
45 country,
46 temp_unit
47 ).unwrap()
48}
49
50fn main() {
51 rocket::ignite()
52 .mount("/", routes![weather, forecast])
53 .launch();
54
55}