Start ivago calendar endpoint

This commit is contained in:
Jef Roosens 2021-03-21 16:18:53 +01:00
parent b42ea850cd
commit c6d29f329c
Signed by: Jef Roosens
GPG key ID: B580B976584B5F30
5 changed files with 66 additions and 14 deletions

View file

@ -1,5 +1,7 @@
mod search;
mod pickup_times;
pub use search::{Street, search_streets};
pub use pickup_times::{get_pickup_times, PickupTime};
///// Return the known pickup times for the given street and/or city

View file

@ -1,19 +1,27 @@
use std::error::Error;
use chrono::NaiveDate;
use super::search::Street;
const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling";
/// Represents a timezoneless date
pub struct Date {
day: u8,
month: u8,
year: u32,
}
/// Represents a pickup time instance. All fields are a direct map of the
/// original API
pub struct PickupTime {
date: Date,
date: NaiveDate,
label: String,
classes: Vec<String>,
url: String
}
pub fn get_pickup_times(
street: Street,
number: u64,
start_date: NaiveDate,
end_date: NaiveDate
) -> Result<Vec<PickupTime>, Box<dyn Error>> {
Ok(Vec::new())
}

View file

@ -2,10 +2,11 @@
mod controller;
use rocket_contrib::json::Json;
use chrono::NaiveDate;
pub fn routes() -> Vec<rocket::Route> {
routes![
search_streets_json,
route_search_streets,
]
}
@ -13,12 +14,19 @@ pub fn routes() -> Vec<rocket::Route> {
// TODO make this async
// TODO change this so it can return errors instead of empty json
#[get("/search?<street>", format="json")]
pub fn search_streets_json(street: String) -> Json<Vec<controller::Street>> {
pub fn route_search_streets(street: String) -> Json<Vec<controller::Street>> {
match controller::search_streets(&street) {
Ok(streets) => Json(streets),
Err(err) => {
println!("{:?}", err);
Json(Vec::new())
},
Err(err) => Json(Vec::new()),
}
}
#[get("/?<street>&<number>&<start_date>&<end_date>")]
pub fn route_get_pickup_times(
street: controller::Street,
number: u64,
start_date: NaiveDate,
end_date: NaiveDate
) -> Json<Vec<controller::PickupTime>> {
}