Adding fetch_item, but need to expand what an ID can be

This commit is contained in:
Julia Lange 2026-02-04 13:52:22 -08:00
parent 25f00d1665
commit f2e00afbb9
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto
4 changed files with 59 additions and 2 deletions

View file

@ -4,6 +4,8 @@ mod feed;
pub use feed::Feed; pub use feed::Feed;
mod feed_channel; mod feed_channel;
pub use feed_channel::FeedChannel; pub use feed_channel::FeedChannel;
mod feed_item;
pub use feed_item::FeedItem;
mod channel; mod channel;
pub use channel::Channel; pub use channel::Channel;
mod item; mod item;

View file

@ -72,7 +72,6 @@ impl FeedChannel {
).execute(&pool.0).await?; ).execute(&pool.0).await?;
Ok(()) Ok(())
} }
} }
#[cfg(test)] #[cfg(test)]

View file

@ -0,0 +1,56 @@
use chrono::{DateTime, Utc};
use crate::{
Result,
AdapterPool,
db::{
ItemId,
FeedId,
},
score::{
TimedScore,
UnparsedTimedScore,
},
};
pub struct UnparsedFeedItem {
pub item_id: i64,
pub feed_id: i64,
pub score: i64,
pub last_updated: String,
pub boosted_at: Option<String>,
}
impl UnparsedFeedItem {
pub fn parse(self) -> Result<FeedItem> {
Ok(FeedItem {
item_id: ItemId(self.item_id),
feed_id: FeedId(self.feed_id),
score: (UnparsedTimedScore {
value: self.score,
last_updated: DateTime::parse_from_rfc2822(&self.last_updated)?
.with_timezone(&Utc),
last_boosted: self.boosted_at.as_deref()
.map(DateTime::parse_from_rfc2822)
.transpose()?
.map(|dt| dt.with_timezone(&Utc)),
}).parse(),
})
}
}
pub struct FeedItem {
item_id: ItemId,
feed_id: FeedId,
score: TimedScore,
}
impl FeedItem {
// async fn boost(pool: &AdapterPool, boost: Boost) -> Result<()> {
// self.boost_at(pool, boost, Utc::now()).await
// }
//
// async fn boost_at(
// &self, pool: &AdapterPool, boost: Boost, boost_at: DateTime<Utc>
// ) -> Result<()> {
//
// }
}

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
Result, Result,
db::Channel, db::{Channel, ChannelId},
AdapterClient, AdapterClient,
}; };
use reqwest::Url; use reqwest::Url;