[#9] Moved calendar function to new errors system

master
Jef Roosens 2021-04-04 14:14:14 +02:00
parent eab31e5e91
commit df6e245030
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
3 changed files with 7 additions and 13 deletions

View File

@ -1,14 +1,14 @@
use super::search::Street; use super::search::Street;
use crate::errors::FejError;
use chrono::{FixedOffset, TimeZone}; use chrono::{FixedOffset, TimeZone};
use regex::Regex; use regex::Regex;
use reqwest::blocking as reqwest; use reqwest::blocking as reqwest;
use rocket::http::RawStr; use rocket::http::RawStr;
use rocket::request::FromFormValue; use rocket::request::FromFormValue;
use serde::ser::{SerializeStruct, Serializer}; use serde::ser::{SerializeStruct, Serializer};
use serde::{Deserialize, Serialize}; use serde::Serialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::{From, TryFrom}; use std::convert::{From, TryFrom};
use std::error::Error;
const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling"; 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"; 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, number: u32,
start_date: BasicDate, start_date: BasicDate,
end_date: BasicDate, end_date: BasicDate,
) -> Result<Vec<PickupTime>, Box<dyn Error>> { ) -> Result<Vec<PickupTime>, FejError> {
let client = reqwest::Client::builder().cookie_store(true).build()?; let client = reqwest::Client::builder().cookie_store(true).build()?;
// This populates the cookies with the necessary values // This populates the cookies with the necessary values

View File

@ -6,7 +6,6 @@ use rocket::request::FromFormValue;
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::error::Error;
/// Endpoint for the search feature /// Endpoint for the search feature
const SEARCH_URL: &str = "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets"; const SEARCH_URL: &str = "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets";

View File

@ -2,7 +2,6 @@ mod controller;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use crate::errors::FejError;
use rocket::http::Status; use rocket::http::Status;
use rocket_contrib::json::Json; use rocket_contrib::json::Json;
@ -10,11 +9,9 @@ pub fn routes() -> Vec<rocket::Route> {
routes![route_search_streets, route_get_pickup_times] routes![route_search_streets, route_get_pickup_times]
} }
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
#[get("/search?<street>")] #[get("/search?<street>")]
pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> { pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> {
let result = controller::search_streets(&street)?; Ok(Json(controller::search_streets(&street)?))
Ok(Json(result))
} }
#[get("/?<street>&<number>&<start_date>&<end_date>")] #[get("/?<street>&<number>&<start_date>&<end_date>")]
@ -24,9 +21,7 @@ pub fn route_get_pickup_times(
start_date: controller::BasicDate, start_date: controller::BasicDate,
end_date: controller::BasicDate, end_date: controller::BasicDate,
) -> Result<Json<Vec<controller::PickupTime>>, Status> { ) -> Result<Json<Vec<controller::PickupTime>>, Status> {
match controller::get_pickup_times(street, number, start_date, end_date) { Ok(Json(controller::get_pickup_times(
// TODO provide more meaningful status codes here street, number, start_date, end_date,
Err(_) => Err(Status::InternalServerError), )?))
Ok(times) => Ok(Json(times)),
}
} }