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