Add demo feed
This commit is contained in:
parent
4cce902a21
commit
2b632f0a93
17
src/demo.rs
17
src/demo.rs
@ -54,5 +54,22 @@ 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.
|
||||||
|
// 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");
|
||||||
}
|
}
|
||||||
|
23
src/feeds.rs
23
src/feeds.rs
@ -12,13 +12,13 @@ use crate::Db;
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
pub struct Feed {
|
pub struct Feed {
|
||||||
feed_id: Uuid,
|
pub feed_id: Uuid,
|
||||||
name: String,
|
pub name: String,
|
||||||
url: Url,
|
pub url: Url,
|
||||||
user_id: Uuid,
|
pub user_id: Uuid,
|
||||||
added_time: chrono::DateTime<chrono::Utc>,
|
pub added_time: chrono::DateTime<chrono::Utc>,
|
||||||
last_checked_time: chrono::DateTime<chrono::Utc>,
|
pub last_checked_time: chrono::DateTime<chrono::Utc>,
|
||||||
categorization: Vec<String>,
|
pub categorization: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Feed {
|
impl Feed {
|
||||||
@ -37,11 +37,10 @@ impl Feed {
|
|||||||
|
|
||||||
pub async fn write_to_database(&self, mut db: Connection<Db>) -> Result<(), sqlx::Error> {
|
pub async fn write_to_database(&self, mut db: Connection<Db>) -> Result<(), sqlx::Error> {
|
||||||
// Convert categorization to JSON value
|
// Convert categorization to JSON value
|
||||||
let categorization_json = serde::json::to_value(&self.categorization)
|
let categorization_json = serde::json::to_value(&self.categorization).map_err(|e| {
|
||||||
.map_err(|e| {
|
eprintln!("Failed to serialize categorization: {}", e);
|
||||||
eprintln!("Failed to serialize categorization: {}", e);
|
sqlx::Error::Decode(Box::new(e))
|
||||||
sqlx::Error::Decode(Box::new(e))
|
})?;
|
||||||
})?;
|
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO feeds (feed_id, name, url, user_id, added_time, last_checked_time, categorization)
|
"INSERT INTO feeds (feed_id, name, url, user_id, added_time, last_checked_time, categorization)
|
||||||
|
Loading…
Reference in New Issue
Block a user