Add feed sidebar navigation #8
2 changed files with 30 additions and 35 deletions
|
|
@ -7,17 +7,16 @@ use diesel_async::RunQueryDsl;
|
||||||
use feedsignal_core::Article;
|
use feedsignal_core::Article;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// `(id, feed_id, title, url, summary, topics, final_score)`, as returned
|
/// One row of [`Db::list_ranked_articles`].
|
||||||
/// by [`Db::list_ranked_articles`].
|
pub struct RankedArticleRow {
|
||||||
type RankedArticleRow = (
|
pub id: String,
|
||||||
String,
|
pub feed_id: String,
|
||||||
String,
|
pub title: String,
|
||||||
String,
|
pub url: String,
|
||||||
String,
|
pub summary: String,
|
||||||
String,
|
pub topics: Vec<String>,
|
||||||
Vec<String>,
|
pub final_score: Option<f32>,
|
||||||
Option<f32>,
|
}
|
||||||
);
|
|
||||||
|
|
||||||
impl Db {
|
impl Db {
|
||||||
pub async fn insert_article(&self, article: &Article) -> Result<()> {
|
pub async fn insert_article(&self, article: &Article) -> Result<()> {
|
||||||
|
|
@ -137,16 +136,14 @@ impl Db {
|
||||||
Ok(rows
|
Ok(rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(
|
.map(
|
||||||
|(id, feed_id, title, url, summary, topics_json, final_score)| {
|
|(id, feed_id, title, url, summary, topics_json, final_score)| RankedArticleRow {
|
||||||
(
|
id,
|
||||||
id,
|
feed_id,
|
||||||
feed_id,
|
title,
|
||||||
title,
|
url,
|
||||||
url,
|
summary,
|
||||||
summary,
|
topics: serde_json::from_str(&topics_json).unwrap_or_default(),
|
||||||
serde_json::from_str(&topics_json).unwrap_or_default(),
|
final_score,
|
||||||
final_score,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.collect())
|
.collect())
|
||||||
|
|
@ -246,7 +243,7 @@ mod tests {
|
||||||
let rows = db.list_ranked_articles(Some(feed_a), 10).await.unwrap();
|
let rows = db.list_ranked_articles(Some(feed_a), 10).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(rows.len(), 1);
|
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
|
/// 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();
|
let rows = db.list_ranked_articles(None, 10).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(rows[0].6, Some(0.8));
|
assert_eq!(rows[0].final_score, Some(0.8));
|
||||||
assert_eq!(rows[1].6, Some(0.2));
|
assert_eq!(rows[1].final_score, Some(0.2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,14 @@ pub async fn list_ranked(db: Db, feed_id: Option<String>) -> Result<Vec<ArticleV
|
||||||
.list_ranked_articles(feed_id, 100)
|
.list_ranked_articles(feed_id, 100)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(
|
.map(|row| ArticleView {
|
||||||
|(id, feed_id, title, url, summary, topics, final_score)| ArticleView {
|
id: row.id,
|
||||||
id,
|
feed_id: row.feed_id,
|
||||||
feed_id,
|
title: row.title,
|
||||||
title,
|
url: row.url,
|
||||||
url,
|
summary: row.summary,
|
||||||
summary,
|
topics: row.topics,
|
||||||
topics,
|
final_score: row.final_score,
|
||||||
final_score,
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue