feat: working reservation api

This commit is contained in:
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;
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::<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);
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 {
#[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<String>,
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<String>,
pub user_validation: bool,