Compare commits
2 Commits
241bb3fba4
...
7ecf598aa8
Author | SHA1 | Date | |
---|---|---|---|
|
7ecf598aa8 | ||
|
286f4273bf |
21
src/demo.rs
21
src/demo.rs
@ -1,6 +1,7 @@
|
|||||||
use crate::feeds::Feed;
|
use crate::feeds::Feed;
|
||||||
|
use crate::poll_utils::fetch_new_entries;
|
||||||
use crate::user::User;
|
use crate::user::User;
|
||||||
use tracing::info;
|
use tracing::{info, warn};
|
||||||
|
|
||||||
struct DemoFeed {
|
struct DemoFeed {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
@ -76,22 +77,24 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for feed in feeds {
|
for feed in feeds.iter() {
|
||||||
feed.write_to_database(pool)
|
feed.write_to_database(pool)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create demo feed");
|
.expect("Failed to create demo feed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
for feed in feeds.iter() {
|
||||||
for feed in feeds {
|
let url = &feed.url;
|
||||||
let url = feed.url;
|
|
||||||
|
|
||||||
let entries = match fetch_new_entries(&url).await {
|
|
||||||
|
|
||||||
|
let entries = match fetch_new_entries(url).await {
|
||||||
|
Ok(entries) => entries,
|
||||||
|
Err(e) => {
|
||||||
|
warn!(error=%e, feed_url=url.as_str(), "Error populating feed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
update_entry_db(&entries, &feed_id, &mut db).await?;
|
//update_entry_db(&entries, &feed_id, &mut db).await?;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
info!("Successfully set up demo data");
|
info!("Successfully set up demo data");
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ pub struct EntryStateUpdate {
|
|||||||
read: Option<bool>,
|
read: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_entries(feed_id: &str, db: &mut SqliteConnection) -> Result<Vec<Entry>, Status> {
|
async fn read_entries(feed_id: &Uuid, db: &mut SqliteConnection) -> Result<Vec<Entry>, Status> {
|
||||||
let rows = sqlx::query!(
|
let rows = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
SELECT
|
SELECT
|
||||||
@ -86,13 +86,13 @@ pub async fn poll_feed(
|
|||||||
feed_id: Uuid,
|
feed_id: Uuid,
|
||||||
user: AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
) -> Result<Json<FeedPollResponse>, Status> {
|
) -> Result<Json<FeedPollResponse>, Status> {
|
||||||
let feed_id = feed_id.to_string();
|
|
||||||
let user_id = user.user_id.to_string();
|
let user_id = user.user_id.to_string();
|
||||||
|
|
||||||
|
let feed_id_str = feed_id.to_string();
|
||||||
// Get the feed URL from the database, ensuring it belongs to the authenticated user
|
// Get the feed URL from the database, ensuring it belongs to the authenticated user
|
||||||
let feed = sqlx::query!(
|
let feed = sqlx::query!(
|
||||||
r#"SELECT url, last_checked_time as "last_checked_time: chrono::DateTime<chrono::Utc>" FROM feeds WHERE feed_id = ? AND user_id = ?"#,
|
r#"SELECT url, last_checked_time as "last_checked_time: chrono::DateTime<chrono::Utc>" FROM feeds WHERE feed_id = ? AND user_id = ?"#,
|
||||||
feed_id,
|
feed_id_str,
|
||||||
user_id
|
user_id
|
||||||
)
|
)
|
||||||
.fetch_optional(&mut **db)
|
.fetch_optional(&mut **db)
|
||||||
|
@ -23,7 +23,6 @@ pub struct Entry {
|
|||||||
pub marked_read: Option<DateTime<Utc>>,
|
pub marked_read: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Perform the request to fetch from the remote feed url
|
/// Perform the request to fetch from the remote feed url
|
||||||
pub async fn fetch_new_entries(url: &Url) -> Result<Vec<Entry>, Status> {
|
pub async fn fetch_new_entries(url: &Url) -> Result<Vec<Entry>, Status> {
|
||||||
let feed_data = fetch_feed(url).await.map_err(|_| Status::BadGateway)?;
|
let feed_data = fetch_feed(url).await.map_err(|_| Status::BadGateway)?;
|
||||||
@ -53,7 +52,7 @@ pub async fn fetch_new_entries(url: &Url) -> Result<Vec<Entry>, Status> {
|
|||||||
|
|
||||||
pub async fn update_entry_db(
|
pub async fn update_entry_db(
|
||||||
entries: &Vec<Entry>,
|
entries: &Vec<Entry>,
|
||||||
feed_id: &str,
|
feed_id: &Uuid,
|
||||||
db: &mut SqliteConnection,
|
db: &mut SqliteConnection,
|
||||||
) -> Result<(), Status> {
|
) -> Result<(), Status> {
|
||||||
// Start a transaction for batch update
|
// Start a transaction for batch update
|
||||||
@ -65,6 +64,7 @@ pub async fn update_entry_db(
|
|||||||
let now = Utc::now().to_rfc3339();
|
let now = Utc::now().to_rfc3339();
|
||||||
|
|
||||||
// Update the feed's last_checked_time
|
// Update the feed's last_checked_time
|
||||||
|
let feed_id = feed_id.to_string();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE feeds SET last_checked_time = ? WHERE feed_id = ?",
|
"UPDATE feeds SET last_checked_time = ? WHERE feed_id = ?",
|
||||||
now,
|
now,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user