From 5a0aa72066ecfb2ec8ad4c798c6446a23da88626 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 3 Feb 2025 20:29:20 -0800 Subject: [PATCH] Use categorizations --- src/demo.rs | 8 +++++++- src/feeds.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/demo.rs b/src/demo.rs index 90c1d30..f2dd562 100644 --- a/src/demo.rs +++ b/src/demo.rs @@ -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"); diff --git a/src/feeds.rs b/src/feeds.rs index 4aaa124..012509d 100644 --- a/src/feeds.rs +++ b/src/feeds.rs @@ -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?;