2021-03-15 14:48:20 +01:00
|
|
|
mod controller;
|
2021-04-02 21:20:36 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2021-03-06 00:25:40 +01:00
|
|
|
|
2021-04-05 10:48:10 +02:00
|
|
|
use controller::structs::{BasicDate, PickupTime, Street};
|
|
|
|
use controller::{get_pickup_times, search_streets};
|
2021-04-03 20:47:39 +02:00
|
|
|
use rocket::http::Status;
|
2021-04-02 21:20:36 +02:00
|
|
|
use rocket_contrib::json::Json;
|
2021-03-12 22:17:59 +01:00
|
|
|
|
2021-03-06 00:25:40 +01:00
|
|
|
pub fn routes() -> Vec<rocket::Route> {
|
2021-04-04 09:57:19 +02:00
|
|
|
routes![route_search_streets, route_get_pickup_times]
|
2021-03-06 00:25:40 +01:00
|
|
|
}
|
|
|
|
|
2021-03-23 12:16:01 +01:00
|
|
|
#[get("/search?<street>")]
|
2021-04-05 10:48:10 +02:00
|
|
|
pub fn route_search_streets(street: String) -> Result<Json<Vec<Street>>, Status> {
|
2021-04-05 11:10:48 +02:00
|
|
|
Ok(Json(search_streets(street.as_str())?))
|
2021-03-06 00:25:40 +01:00
|
|
|
}
|
2021-03-21 16:18:53 +01:00
|
|
|
|
|
|
|
#[get("/?<street>&<number>&<start_date>&<end_date>")]
|
|
|
|
pub fn route_get_pickup_times(
|
2021-04-05 10:48:10 +02:00
|
|
|
street: Street,
|
2021-04-03 20:47:39 +02:00
|
|
|
number: u32,
|
2021-04-05 10:48:10 +02:00
|
|
|
start_date: BasicDate,
|
|
|
|
end_date: BasicDate,
|
|
|
|
) -> Result<Json<Vec<PickupTime>>, Status> {
|
|
|
|
Ok(Json(get_pickup_times(
|
2021-04-04 14:14:14 +02:00
|
|
|
street, number, start_date, end_date,
|
|
|
|
)?))
|
2021-03-21 16:18:53 +01:00
|
|
|
}
|