feat: working reservation api

dev
Jef Roosens 2023-05-11 21:35:28 +02:00
parent 0deb67478f
commit 0d144f3b61
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 31 additions and 11 deletions

View File

@ -1,7 +1,7 @@
mod models; mod models;
pub use models::*;
use chrono::NaiveDate; 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"; 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::<Data<SiteData>>().await?.data) Ok(self.client.get(url).send().await?.json::<Data<SiteData>>().await?.data)
} }
pub async fn make_reservation(&mut self, resource_id: u64, reservation: &Reservation) -> reqwest::Result<ReservationResponse> { pub async fn make_reservation(&mut self, resource_id: u32, reservation: &Reservation) -> reqwest::Result<ReservationResponse> {
let url = format!("https://reservation.affluences.com/api/reserve/{}", resource_id); let url = format!("https://reservation.affluences.com/api/reserve/{}", resource_id);
self.client.get(url).json(reservation).send().await?.json::<ReservationResponse>().await self.client.post(url).json(reservation).send().await?.json::<ReservationResponse>().await
} }
} }

View File

@ -29,7 +29,7 @@ mod time_format {
} }
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug, Clone, Copy)]
pub struct Hour { pub struct Hour {
#[serde(with = "time_format")] #[serde(with = "time_format")]
pub hour: NaiveTime, pub hour: NaiveTime,
@ -105,7 +105,7 @@ pub struct SiteDataLocation {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct SiteDataForecast { pub struct SiteDataForecast {
pub opened: bool, pub opened: bool,
pub occupancy: u64, pub occupancy: u32,
// waiting_time // waiting_time
pub waiting_time_overflow: bool pub waiting_time_overflow: bool
} }
@ -118,7 +118,7 @@ pub struct SiteDataNotice {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct SiteDataService { pub struct SiteDataService {
pub id: u64, pub id: u32,
pub name: String, pub name: String,
} }
@ -188,12 +188,12 @@ pub struct Reservation {
pub user_firstname: String, pub user_firstname: String,
pub user_lastname: String, pub user_lastname: String,
pub user_phone: Option<String>, pub user_phone: Option<String>,
pub person_count: u64 pub person_count: u32
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct ReservationResponse { pub struct ReservationResponse {
pub reservation_id: u64, pub reservation_id: u32,
// This string might not be correct // This string might not be correct
pub auth_type: Option<String>, pub auth_type: Option<String>,
pub user_validation: bool, pub user_validation: bool,

View File

@ -1,4 +1,4 @@
use affluences_api::AffluencesClient; use affluences_api::{AffluencesClient, Reservation};
use chrono::NaiveDate; use chrono::NaiveDate;
use uuid::{uuid, Uuid}; use uuid::{uuid, Uuid};
@ -10,9 +10,29 @@ async fn main() {
// let res = client.site_data(site).await.unwrap(); // let res = client.site_data(site).await.unwrap();
let date = NaiveDate::from_ymd_opt(2023, 5, 12).unwrap();
let res = client let res = client
.available(id, NaiveDate::from_ymd_opt(2023, 5, 11).unwrap(), 1) .available(id, date, 1)
.await .await
.unwrap(); .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);
} }