diff --git a/affluences-api/src/lib.rs b/affluences-api/src/lib.rs index 6f7bbbc..c4b5ad8 100644 --- a/affluences-api/src/lib.rs +++ b/affluences-api/src/lib.rs @@ -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"; diff --git a/affluences-api/src/models.rs b/affluences-api/src/models.rs index 43f93ca..01ba2f9 100644 --- a/affluences-api/src/models.rs +++ b/affluences-api/src/models.rs @@ -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( + time: &NaiveTime, + serializer: S, + ) -> Result + where + S: Serializer, + { + let s = format!("{}", time.format(FORMAT)); + serializer.serialize_str(&s) + } + + pub fn deserialize<'de, D>( + deserializer: D, + ) -> Result + 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 } -#[derive(Deserialize, Debug)] -pub struct SiteDataChild { - pub id: uuid::Uuid, - pub slug: String, - pub parent: Option, - pub primary_name: String, - pub secondary_name: String, - pub concat_name: String, - pub categories: Vec, - pub time_zone: String, - pub location: SiteDataLocation, - pub phone_number: String, - pub email: String, - pub url: String, - pub notices: Vec, - // messages - pub estimated_distance: f64, - pub current_forecast: SiteDataForecast, - pub today_forecasts: Vec, - // 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, 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,