2021-03-06 00:25:40 +01:00
|
|
|
#[cfg(test)] mod tests;
|
2021-03-15 14:48:20 +01:00
|
|
|
mod controller;
|
2021-03-06 00:25:40 +01:00
|
|
|
|
2021-03-12 22:17:59 +01:00
|
|
|
use rocket_contrib::json::Json;
|
|
|
|
|
2021-03-06 00:25:40 +01:00
|
|
|
pub fn routes() -> Vec<rocket::Route> {
|
2021-03-11 20:52:30 +01:00
|
|
|
routes![
|
2021-03-15 14:48:20 +01:00
|
|
|
search_streets_json,
|
2021-03-11 20:52:30 +01:00
|
|
|
]
|
2021-03-06 00:25:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
2021-03-12 22:17:59 +01:00
|
|
|
// TODO make this async
|
|
|
|
// TODO change this so it can return errors instead of empty json
|
2021-03-12 00:16:48 +01:00
|
|
|
#[get("/search?<street>", format="json")]
|
2021-03-15 14:48:20 +01:00
|
|
|
pub fn search_streets_json(street: String) -> Json<Vec<controller::Street>> {
|
|
|
|
match controller::search_streets(&street) {
|
2021-03-12 22:17:59 +01:00
|
|
|
Ok(streets) => Json(streets),
|
|
|
|
Err(err) => {
|
|
|
|
println!("{:?}", err);
|
|
|
|
Json(Vec::new())
|
|
|
|
},
|
|
|
|
}
|
2021-03-06 00:25:40 +01:00
|
|
|
}
|