207 lines
5.0 KiB
Rust
207 lines
5.0 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use chrono::{NaiveTime, NaiveDate};
|
|
|
|
mod time_format {
|
|
use chrono::NaiveTime;
|
|
use serde::{self, Deserialize, Serializer, Deserializer};
|
|
|
|
const FORMAT: &'static str = "%H:%M";
|
|
|
|
pub fn serialize<S>(
|
|
time: &NaiveTime,
|
|
serializer: S,
|
|
) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
let s = format!("{}", time.format(FORMAT));
|
|
serializer.serialize_str(&s)
|
|
}
|
|
|
|
pub fn deserialize<'de, D>(
|
|
deserializer: D,
|
|
) -> Result<NaiveTime, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let s = String::deserialize(deserializer)?;
|
|
NaiveTime::parse_from_str(&s, FORMAT).map_err(serde::de::Error::custom)
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Clone, Copy)]
|
|
pub struct Hour {
|
|
#[serde(with = "time_format")]
|
|
pub hour: NaiveTime,
|
|
pub state: u32,
|
|
// reservations
|
|
pub granularity: u32,
|
|
pub person_count: u32,
|
|
pub places_available: u32,
|
|
pub places_bookable: u32,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Resource {
|
|
pub resource_id: u32,
|
|
pub resource_name: String,
|
|
pub resource_type: u32,
|
|
pub granularity: u32,
|
|
pub time_slot_count: u32,
|
|
pub static_time_slot: bool,
|
|
// reservations_by_timeslot
|
|
pub note_available: bool,
|
|
pub note_required: bool,
|
|
pub note_description: String,
|
|
pub description: String,
|
|
pub capacity: u32,
|
|
pub site_timezone: String,
|
|
pub user_name_required: bool,
|
|
pub user_phone_required: bool,
|
|
pub user_name_available: bool,
|
|
pub user_phone_available: bool,
|
|
// time_before_reservations_closed
|
|
// min_places_per_reservation
|
|
// max_places_per_reservation
|
|
pub image_url: Option<String>,
|
|
// services
|
|
pub slots_state: u32,
|
|
pub hours: Vec<Hour>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Data<T> {
|
|
pub data: T
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataCategory {
|
|
pub id: u32,
|
|
pub name: String,
|
|
pub name_plural: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataLocationCoordinates {
|
|
pub latitude: f64,
|
|
pub longitude: f64,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataLocationAddress {
|
|
pub route: String,
|
|
pub city: String,
|
|
pub zip_code: String,
|
|
pub region: String,
|
|
pub country_code: String
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataLocation {
|
|
pub coordinates: SiteDataLocationCoordinates,
|
|
pub address: SiteDataLocationAddress
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataForecast {
|
|
pub opened: bool,
|
|
pub occupancy: u32,
|
|
// waiting_time
|
|
pub waiting_time_overflow: bool
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataNotice {
|
|
pub message: String,
|
|
pub url: Option<String>
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataService {
|
|
pub id: u32,
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataInfo {
|
|
pub title: String,
|
|
pub description: String,
|
|
pub url: Option<String>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteDataStatus {
|
|
pub state: String,
|
|
pub text: String,
|
|
pub color: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SiteData {
|
|
pub id: uuid::Uuid,
|
|
pub slug: String,
|
|
pub parent: Option<String>,
|
|
pub primary_name: String,
|
|
pub secondary_name: String,
|
|
pub concat_name: String,
|
|
pub categories: Vec<SiteDataCategory>,
|
|
pub time_zone: String,
|
|
pub location: SiteDataLocation,
|
|
pub phone_number: Option<String>,
|
|
pub email: Option<String>,
|
|
pub url: Option<String>,
|
|
pub notices: Vec<SiteDataNotice>,
|
|
// messages
|
|
pub estimated_distance: f64,
|
|
pub current_forecast: SiteDataForecast,
|
|
pub today_forecasts: Vec<SiteDataForecast>,
|
|
// events
|
|
pub children: Vec<SiteData>,
|
|
// actions
|
|
pub services: Vec<SiteDataService>,
|
|
pub infos: Vec<SiteDataInfo>,
|
|
pub poster_image: String,
|
|
pub image: Option<Vec<String>>,
|
|
// status
|
|
pub closed: bool,
|
|
pub booking_available: bool,
|
|
pub extended_forecasts: bool,
|
|
pub booking_url: Option<String>,
|
|
pub validated: bool,
|
|
#[serde(rename = "validationStatus")]
|
|
pub validation_status: String,
|
|
#[serde(rename = "publicationStatus")]
|
|
pub publication_status: String
|
|
}
|
|
|
|
#[derive(Serialize, Debug)]
|
|
pub struct Reservation {
|
|
// This string might not be correct
|
|
pub auth_type: Option<String>,
|
|
pub email: String,
|
|
pub date: NaiveDate,
|
|
#[serde(with = "time_format")]
|
|
pub start_time: NaiveTime,
|
|
#[serde(with = "time_format")]
|
|
pub end_time: NaiveTime,
|
|
pub note: String,
|
|
pub user_firstname: String,
|
|
pub user_lastname: String,
|
|
pub user_phone: Option<String>,
|
|
pub person_count: u32
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct ReservationResponse {
|
|
pub reservation_id: u32,
|
|
// This string might not be correct
|
|
pub auth_type: Option<String>,
|
|
pub user_validation: bool,
|
|
// ticket_payload
|
|
pub email: String,
|
|
pub success: String,
|
|
#[serde(rename = "successMessage")]
|
|
pub success_message: String,
|
|
// cancellation_token
|
|
}
|