diff --git a/src/demo.rs b/src/demo.rs index 0e90179..7f3601d 100644 --- a/src/demo.rs +++ b/src/demo.rs @@ -46,7 +46,7 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) { .await .expect("Failed to create demo user"); - let feed = Feed::new( + let bbc_news = Feed::new( "BBC News".to_string(), "https://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml" .parse() @@ -54,22 +54,38 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) { demo_id, ); - // TODO: This insert logic is substantially the same as Feed::write_to_database. - // Should find a way to unify these two code paths to avoid duplication. - sqlx::query( - "INSERT INTO feeds (feed_id, name, url, user_id, added_time, last_checked_time, categorization) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, json(?7))", - ) - .bind(feed.feed_id.to_string()) - .bind(&feed.name) - .bind(feed.url.as_str()) - .bind(feed.user_id.to_string()) - .bind(feed.added_time.to_rfc3339()) - .bind(feed.last_checked_time.to_rfc3339()) - .bind("[]") // empty categorization array as JSON - .execute(pool) - .await - .expect("Failed to create demo feed"); + let xkcd = Feed::new( + "XKCD".to_string(), + "https://xkcd.com/atom.xml".parse().unwrap(), + demo_id, + ); + + let isidore = Feed::new( + "Isidore & Friends".to_string(), + "https://isidore.webcomic.ws/rss/".parse().unwrap(), + demo_id, + ); + + let feeds = [bbc_news, xkcd, isidore]; + + for feed in feeds { + // TODO: This insert logic is substantially the same as Feed::write_to_database. + // Should find a way to unify these two code paths to avoid duplication. + sqlx::query( + "INSERT INTO feeds (feed_id, name, url, user_id, added_time, last_checked_time, categorization) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, json(?7))", + ) + .bind(feed.feed_id.to_string()) + .bind(&feed.name) + .bind(feed.url.as_str()) + .bind(feed.user_id.to_string()) + .bind(feed.added_time.to_rfc3339()) + .bind(feed.last_checked_time.to_rfc3339()) + .bind("[]") // empty categorization array as JSON + .execute(pool) + .await + .expect("Failed to create demo feed"); + } println!("Successfully set up demo data"); } diff --git a/src/main.rs b/src/main.rs index 9533c02..1baddc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ mod user; use rocket::fairing::{self, AdHoc}; use rocket::fs::FileServer; use rocket::response::Redirect; -use rocket::{Build, Rocket}; +use rocket::{Build, Rocket, State}; use rocket_db_pools::{sqlx, Connection, Database}; use rocket_dyn_templates::{context, Template}; use user::AuthenticatedUser; @@ -58,7 +58,7 @@ async fn index_redirect(mut db: Connection) -> Redirect { #[get("/login")] fn login(demo_mode: &State) -> Template { - Template::render("login", context! { demo_mode: *demo_mode }) + Template::render("login", context! { demo_mode: **demo_mode }) } // Run migrations and setup demo data if needed