Start working with entries

This commit is contained in:
Greg Shuflin 2025-02-02 22:22:42 -08:00
parent 3ca699b948
commit 18f51ed741

View File

@ -9,6 +9,14 @@ use rocket_db_pools::Connection;
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]
pub struct FeedPollResponse { pub struct FeedPollResponse {
count: usize, count: usize,
entries: Vec<Entry>,
}
#[derive(Debug, Serialize)]
#[serde(crate = "rocket::serde")]
struct Entry {
id: String,
title: String,
} }
#[post("/poll/<feed_id>")] #[post("/poll/<feed_id>")]
@ -36,7 +44,19 @@ pub async fn poll_feed(
let feed_data = fetch_feed(&url).await.map_err(|_| Status::BadGateway)?; let feed_data = fetch_feed(&url).await.map_err(|_| Status::BadGateway)?;
Ok(Json(FeedPollResponse { let count = feed_data.entries.len();
count: feed_data.entries.len(),
})) let entries = feed_data
.entries
.into_iter()
.map(|feed_entry| Entry {
id: feed_entry.id,
title: feed_entry
.title
.map(|t| t.content)
.unwrap_or("<no title>".to_string()),
})
.collect();
Ok(Json(FeedPollResponse { count, entries }))
} }