Compare commits
No commits in common. "27a61f8a9a1571793f50880ffbad01a4a9da1551" and "e3f134a9bf770664078e1b2ad85d57bf48a6b710" have entirely different histories.
27a61f8a9a
...
e3f134a9bf
|
@ -1,7 +1,5 @@
|
|||
use super::search::Street;
|
||||
use chrono::NaiveDate;
|
||||
use rocket::http::RawStr;
|
||||
use rocket::request::FromFormValue;
|
||||
use std::error::Error;
|
||||
|
||||
const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling";
|
||||
|
@ -15,17 +13,6 @@ pub struct PickupTime {
|
|||
url: String,
|
||||
}
|
||||
|
||||
impl<'v> FromFormValue<'v> for NaiveDate {
|
||||
type Error = &'v RawStr;
|
||||
|
||||
fn from_form_value(form_value: &'v RawStr) -> Result<NaiveDate, &'v RawStr> {
|
||||
match NaiveDate::parse_from_str(form_value, "%Y-%m-%d") {
|
||||
Ok(date) => Ok(date),
|
||||
Err(_) => Err(form_value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_pickup_times(
|
||||
street: Street,
|
||||
number: u64,
|
||||
|
|
|
@ -3,7 +3,6 @@ mod controller;
|
|||
mod tests;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use rocket::http::Status;
|
||||
use rocket_contrib::json::Json;
|
||||
|
||||
pub fn routes() -> Vec<rocket::Route> {
|
||||
|
@ -11,20 +10,21 @@ pub fn routes() -> Vec<rocket::Route> {
|
|||
}
|
||||
|
||||
// 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>")]
|
||||
pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> {
|
||||
pub fn search_streets_json(street: String) -> Json<Vec<controller::Street>> {
|
||||
match controller::search_streets(&street) {
|
||||
Ok(streets) => Ok(Json(streets)),
|
||||
Err(err) => Err(Status::InternalServerError),
|
||||
Ok(streets) => Json(streets),
|
||||
Err(err) => Json(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/?<street>&<number>&<start_date>&<end_date>")]
|
||||
pub fn route_get_pickup_times(
|
||||
street: controller::Street,
|
||||
number: u32,
|
||||
number: u64,
|
||||
start_date: NaiveDate,
|
||||
end_date: NaiveDate,
|
||||
) -> Result<Json<Vec<controller::PickupTime>>, Status> {
|
||||
Err(Status::InternalServerError)
|
||||
) -> Json<Vec<controller::PickupTime>> {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue