[#4] We now properly return error values
parent
e3f134a9bf
commit
e3174f21af
|
@ -3,6 +3,7 @@ mod controller;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use rocket::http::Status;
|
||||||
use rocket_contrib::json::Json;
|
use rocket_contrib::json::Json;
|
||||||
|
|
||||||
pub fn routes() -> Vec<rocket::Route> {
|
pub fn routes() -> Vec<rocket::Route> {
|
||||||
|
@ -10,21 +11,20 @@ pub fn routes() -> Vec<rocket::Route> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
||||||
// TODO make this async
|
|
||||||
// TODO change this so it can return errors instead of empty json
|
|
||||||
#[get("/search?<street>")]
|
#[get("/search?<street>")]
|
||||||
pub fn search_streets_json(street: String) -> Json<Vec<controller::Street>> {
|
pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> {
|
||||||
match controller::search_streets(&street) {
|
match controller::search_streets(&street) {
|
||||||
Ok(streets) => Json(streets),
|
Ok(streets) => Ok(Json(streets)),
|
||||||
Err(err) => Json(Vec::new()),
|
Err(err) => Err(Status::InternalServerError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/?<street>&<number>&<start_date>&<end_date>")]
|
#[get("/?<street>&<number>&<start_date>&<end_date>")]
|
||||||
pub fn route_get_pickup_times(
|
pub fn route_get_pickup_times(
|
||||||
street: controller::Street,
|
street: controller::Street,
|
||||||
number: u64,
|
number: u32,
|
||||||
start_date: NaiveDate,
|
start_date: NaiveDate,
|
||||||
end_date: NaiveDate,
|
end_date: NaiveDate,
|
||||||
) -> Json<Vec<controller::PickupTime>> {
|
) -> Result<Json<Vec<controller::PickupTime>>, Status> {
|
||||||
|
Err(Status::InternalServerError)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue