diff --git a/affluences-api/src/lib.rs b/affluences-api/src/lib.rs index c4b5ad8..57d103f 100644 --- a/affluences-api/src/lib.rs +++ b/affluences-api/src/lib.rs @@ -1,7 +1,7 @@ mod models; +pub use models::*; use chrono::NaiveDate; -use models::{Resource, Data, SiteData, Reservation, ReservationResponse}; const USER_AGENT: &str = "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0"; @@ -27,8 +27,8 @@ impl AffluencesClient { Ok(self.client.get(url).send().await?.json::>().await?.data) } - pub async fn make_reservation(&mut self, resource_id: u64, reservation: &Reservation) -> reqwest::Result { + pub async fn make_reservation(&mut self, resource_id: u32, reservation: &Reservation) -> reqwest::Result { let url = format!("https://reservation.affluences.com/api/reserve/{}", resource_id); - self.client.get(url).json(reservation).send().await?.json::().await + self.client.post(url).json(reservation).send().await?.json::().await } } diff --git a/affluences-api/src/models.rs b/affluences-api/src/models.rs index 01ba2f9..0dceb3d 100644 --- a/affluences-api/src/models.rs +++ b/affluences-api/src/models.rs @@ -29,7 +29,7 @@ mod time_format { } } -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Clone, Copy)] pub struct Hour { #[serde(with = "time_format")] pub hour: NaiveTime, @@ -105,7 +105,7 @@ pub struct SiteDataLocation { #[derive(Deserialize, Debug)] pub struct SiteDataForecast { pub opened: bool, - pub occupancy: u64, + pub occupancy: u32, // waiting_time pub waiting_time_overflow: bool } @@ -118,7 +118,7 @@ pub struct SiteDataNotice { #[derive(Deserialize, Debug)] pub struct SiteDataService { - pub id: u64, + pub id: u32, pub name: String, } @@ -188,12 +188,12 @@ pub struct Reservation { pub user_firstname: String, pub user_lastname: String, pub user_phone: Option, - pub person_count: u64 + pub person_count: u32 } #[derive(Deserialize, Debug)] pub struct ReservationResponse { - pub reservation_id: u64, + pub reservation_id: u32, // This string might not be correct pub auth_type: Option, pub user_validation: bool, diff --git a/bot/src/main.rs b/bot/src/main.rs index 44ab3f7..4fb0e30 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -1,4 +1,4 @@ -use affluences_api::AffluencesClient; +use affluences_api::{AffluencesClient, Reservation}; use chrono::NaiveDate; use uuid::{uuid, Uuid}; @@ -10,9 +10,29 @@ async fn main() { // let res = client.site_data(site).await.unwrap(); + let date = NaiveDate::from_ymd_opt(2023, 5, 12).unwrap(); let res = client - .available(id, NaiveDate::from_ymd_opt(2023, 5, 11).unwrap(), 1) + .available(id, date, 1) .await .unwrap(); - println!("{:?}", res); + let first = res.first().unwrap(); + let hour = first.hours[0]; + let reservation = Reservation{ + auth_type: None, + email: String::from("mark.verbeken@ugent.be"), + date: date, + start_time: hour.hour, + end_time: hour.hour + chrono::Duration::minutes(30), + note: String::from("hello"), + user_firstname: String::from("Mark"), + user_lastname: String::from("Verbeken"), + user_phone: None, + person_count: 1 + }; + println!("{:?}", first); + println!("{:?}", hour); + println!("{:?}", reservation); + + let res2 = client.make_reservation(first.resource_id, &reservation).await; + println!("{:?}", res2); }