Use categorizations
This commit is contained in:
parent
bfbb458c4e
commit
5a0aa72066
@ -1,5 +1,6 @@
|
||||
use chrono;
|
||||
use sqlx;
|
||||
use rocket::serde;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::feeds::Feed;
|
||||
@ -74,6 +75,11 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
|
||||
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.
|
||||
let categorization_json = serde::json::to_value(feed.categorization).map_err(|e| {
|
||||
eprintln!("Failed to serialize categorization: {}", e);
|
||||
sqlx::Error::Decode(Box::new(e))
|
||||
}).unwrap();
|
||||
|
||||
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))",
|
||||
@ -84,7 +90,7 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
|
||||
.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
|
||||
.bind(categorization_json.to_string())
|
||||
.execute(pool)
|
||||
.await
|
||||
.expect("Failed to create demo feed");
|
||||
|
@ -52,7 +52,7 @@ impl Feed {
|
||||
.bind(self.user_id.to_string())
|
||||
.bind(self.added_time.to_rfc3339())
|
||||
.bind(self.last_checked_time.to_rfc3339())
|
||||
.bind(&categorization_json.to_string())
|
||||
.bind(categorization_json.to_string())
|
||||
.execute(&mut **db)
|
||||
.await?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user