[#9] Moved calendar function to new errors system
parent
eab31e5e91
commit
df6e245030
|
@ -1,14 +1,14 @@
|
|||
use super::search::Street;
|
||||
use crate::errors::FejError;
|
||||
use chrono::{FixedOffset, TimeZone};
|
||||
use regex::Regex;
|
||||
use reqwest::blocking as reqwest;
|
||||
use rocket::http::RawStr;
|
||||
use rocket::request::FromFormValue;
|
||||
use serde::ser::{SerializeStruct, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::{From, TryFrom};
|
||||
use std::error::Error;
|
||||
|
||||
const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling";
|
||||
const CAL_URL: &str = "https://www.ivago.be/nl/particulier/garbage/pick-up/pickups";
|
||||
|
@ -108,7 +108,7 @@ pub fn get_pickup_times(
|
|||
number: u32,
|
||||
start_date: BasicDate,
|
||||
end_date: BasicDate,
|
||||
) -> Result<Vec<PickupTime>, Box<dyn Error>> {
|
||||
) -> Result<Vec<PickupTime>, FejError> {
|
||||
let client = reqwest::Client::builder().cookie_store(true).build()?;
|
||||
|
||||
// This populates the cookies with the necessary values
|
||||
|
|
|
@ -6,7 +6,6 @@ use rocket::request::FromFormValue;
|
|||
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::error::Error;
|
||||
|
||||
/// Endpoint for the search feature
|
||||
const SEARCH_URL: &str = "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets";
|
||||
|
|
|
@ -2,7 +2,6 @@ mod controller;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use crate::errors::FejError;
|
||||
use rocket::http::Status;
|
||||
use rocket_contrib::json::Json;
|
||||
|
||||
|
@ -10,11 +9,9 @@ pub fn routes() -> Vec<rocket::Route> {
|
|||
routes![route_search_streets, route_get_pickup_times]
|
||||
}
|
||||
|
||||
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
||||
#[get("/search?<street>")]
|
||||
pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> {
|
||||
let result = controller::search_streets(&street)?;
|
||||
Ok(Json(result))
|
||||
Ok(Json(controller::search_streets(&street)?))
|
||||
}
|
||||
|
||||
#[get("/?<street>&<number>&<start_date>&<end_date>")]
|
||||
|
@ -24,9 +21,7 @@ pub fn route_get_pickup_times(
|
|||
start_date: controller::BasicDate,
|
||||
end_date: controller::BasicDate,
|
||||
) -> Result<Json<Vec<controller::PickupTime>>, Status> {
|
||||
match controller::get_pickup_times(street, number, start_date, end_date) {
|
||||
// TODO provide more meaningful status codes here
|
||||
Err(_) => Err(Status::InternalServerError),
|
||||
Ok(times) => Ok(Json(times)),
|
||||
}
|
||||
Ok(Json(controller::get_pickup_times(
|
||||
street, number, start_date, end_date,
|
||||
)?))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue