diff --git a/crates/db/src/articles.rs b/crates/db/src/articles.rs index 1090937..1b39b6d 100644 --- a/crates/db/src/articles.rs +++ b/crates/db/src/articles.rs @@ -7,17 +7,16 @@ use diesel_async::RunQueryDsl; use feedsignal_core::Article; use uuid::Uuid; -/// `(id, feed_id, title, url, summary, topics, final_score)`, as returned -/// by [`Db::list_ranked_articles`]. -type RankedArticleRow = ( - String, - String, - String, - String, - String, - Vec, - Option, -); +/// One row of [`Db::list_ranked_articles`]. +pub struct RankedArticleRow { + pub id: String, + pub feed_id: String, + pub title: String, + pub url: String, + pub summary: String, + pub topics: Vec, + pub final_score: Option, +} impl Db { pub async fn insert_article(&self, article: &Article) -> Result<()> { @@ -137,16 +136,14 @@ impl Db { Ok(rows .into_iter() .map( - |(id, feed_id, title, url, summary, topics_json, final_score)| { - ( - id, - feed_id, - title, - url, - summary, - serde_json::from_str(&topics_json).unwrap_or_default(), - final_score, - ) + |(id, feed_id, title, url, summary, topics_json, final_score)| RankedArticleRow { + id, + feed_id, + title, + url, + summary, + topics: serde_json::from_str(&topics_json).unwrap_or_default(), + final_score, }, ) .collect()) @@ -246,7 +243,7 @@ mod tests { let rows = db.list_ranked_articles(Some(feed_a), 10).await.unwrap(); assert_eq!(rows.len(), 1); - assert_eq!(rows[0].1, feed_a.to_string()); + assert_eq!(rows[0].feed_id, feed_a.to_string()); } /// Results stay ordered by `final_score` descending regardless of @@ -263,7 +260,7 @@ mod tests { let rows = db.list_ranked_articles(None, 10).await.unwrap(); - assert_eq!(rows[0].6, Some(0.8)); - assert_eq!(rows[1].6, Some(0.2)); + assert_eq!(rows[0].final_score, Some(0.8)); + assert_eq!(rows[1].final_score, Some(0.2)); } } diff --git a/crates/web/src/server/services/articles.rs b/crates/web/src/server/services/articles.rs index d2a8884..c22c410 100644 --- a/crates/web/src/server/services/articles.rs +++ b/crates/web/src/server/services/articles.rs @@ -12,16 +12,14 @@ pub async fn list_ranked(db: Db, feed_id: Option) -> Result