use chrono::NaiveDate; use serde::Deserialize; pub struct AppState { pub mp_tracks: Vec, pub p_tracks: Vec, pub website_news: Vec, pub bibou_quotes: Vec, } impl AppState { pub async fn try_new() -> Self { Self { mp_tracks: serde_json::from_str( &std::fs::read_to_string("content/mp-tracks.json") .expect("mp-tracks.json non trouvé"), ) .expect("JSON invalide"), p_tracks: serde_json::from_str( &std::fs::read_to_string("content/p-tracks.json") .expect("p-tracks.json non trouvé"), ) .expect("JSON invalide"), website_news: { let mut news: Vec = serde_json::from_str( &std::fs::read_to_string("content/web-articles.json") .expect("web-articles.json non trouvé"), ) .expect("JSON invalide"); news.sort_by(|a, b| b.date.cmp(&a.date)); news }, bibou_quotes: serde_json::from_str( &std::fs::read_to_string("content/bibou-quotes.json") .expect("bibou-quotes.json non trouvé"), ) .expect("JSON invalide"), } } } #[derive(Deserialize)] pub struct Track { pub title: String, pub artist: String, pub src: String, pub album: Option, } #[derive(Deserialize)] pub struct WebsiteArticle { pub date: NaiveDate, pub body: String, }