diff --git a/src/demo.rs b/src/demo.rs index e3cbb1b..795f4a3 100644 --- a/src/demo.rs +++ b/src/demo.rs @@ -1,6 +1,35 @@ use crate::feeds::Feed; use crate::user::User; +struct DemoFeed { + name: &'static str, + url: &'static str, + category: &'static str, +} + +const DEMO_FEEDS: [DemoFeed; 4] = [ + DemoFeed { + name: "XKCD", + url: "https://xkcd.com/atom.xml", + category: "Webcomic", + }, + DemoFeed { + name: "Isidore & Friends", + url: "https://isidore.webcomic.ws/rss/", + category: "Webcomic", + }, + DemoFeed { + name: "Astral Codex Ten", + url: "https://www.astralcodexten.com/feed", + category: "Substack", + }, + DemoFeed { + name: "BBC News", + url: "https://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml", + category: "News", + }, +]; + pub async fn setup_demo_data(pool: &sqlx::SqlitePool) { // Create admin user let mut admin = User::new( @@ -26,41 +55,14 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) { .await .expect("Failed to create demo user"); - let demo_id = demo.id; + for demo_feed in DEMO_FEEDS { + let mut feed = Feed::new( + demo_feed.name.to_string(), + demo_feed.url.parse().unwrap(), + demo.id, + ); + feed.categorization = vec![demo_feed.category.to_string()]; - let mut bbc_news = Feed::new( - "BBC News".to_string(), - "https://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml" - .parse() - .unwrap(), - demo_id, - ); - bbc_news.categorization = vec!["News".to_string()]; - - let mut xkcd = Feed::new( - "XKCD".to_string(), - "https://xkcd.com/atom.xml".parse().unwrap(), - demo_id, - ); - xkcd.categorization = vec!["Webcomic".to_string()]; - - let mut isidore = Feed::new( - "Isidore & Friends".to_string(), - "https://isidore.webcomic.ws/rss/".parse().unwrap(), - demo_id, - ); - isidore.categorization = vec!["Webcomic".to_string()]; - - let mut acx = Feed::new( - "Astral Codex Ten".to_string(), - "https://www.astralcodexten.com/feed".parse().unwrap(), - demo_id, - ); - acx.categorization = vec!["Substack".to_string()]; - - let feeds = [bbc_news, xkcd, isidore, acx]; - - for feed in feeds { feed.write_to_database(pool) .await .expect("Failed to create demo feed");