Start ivago calendar endpoint

master
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

33
Cargo.lock generated
View File

@ -152,6 +152,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time 0.1.43",
"winapi 0.3.9",
]
[[package]]
name = "cipher"
version = "0.2.5"
@ -902,6 +915,25 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
@ -1258,6 +1290,7 @@ dependencies = [
name = "rust-api"
version = "0.1.0"
dependencies = [
"chrono",
"reqwest",
"rocket",
"rocket_contrib",

View File

@ -9,6 +9,7 @@ edition = "2018"
[dependencies]
rocket = "0.4.7"
serde = "1.0.124"
chrono = "0.4.19"
[dependencies.reqwest]
version = "0.11.2"

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>> {
}