feat: parse hours
parent
c799d3d226
commit
0deb67478f
|
@ -1,6 +1,6 @@
|
|||
mod models;
|
||||
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
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";
|
||||
|
|
|
@ -1,9 +1,38 @@
|
|||
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)]
|
||||
pub struct Hour {
|
||||
pub hour: String,
|
||||
#[serde(with = "time_format")]
|
||||
pub hour: NaiveTime,
|
||||
pub state: u32,
|
||||
// reservations
|
||||
pub granularity: u32,
|
||||
|
@ -87,34 +116,6 @@ pub struct SiteDataNotice {
|
|||
pub url: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataChild {
|
||||
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: String,
|
||||
pub email: String,
|
||||
pub url: String,
|
||||
pub notices: Vec<SiteDataNotice>,
|
||||
// messages
|
||||
pub estimated_distance: f64,
|
||||
pub current_forecast: SiteDataForecast,
|
||||
pub today_forecasts: Vec<SiteDataForecast>,
|
||||
// events
|
||||
// children
|
||||
// actions
|
||||
// services
|
||||
// infos
|
||||
pub poster_image: String,
|
||||
// images
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataService {
|
||||
pub id: u64,
|
||||
|
@ -179,8 +180,10 @@ pub struct Reservation {
|
|||
pub auth_type: Option<String>,
|
||||
pub email: String,
|
||||
pub date: NaiveDate,
|
||||
pub start_time: String,
|
||||
pub end_time: String,
|
||||
#[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,
|
||||
|
|
Loading…
Reference in New Issue