Adding fetch_item, but need to expand what an ID can be
This commit is contained in:
parent
25f00d1665
commit
f2e00afbb9
4 changed files with 59 additions and 2 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ impl FeedChannel {
|
||||||
).execute(&pool.0).await?;
|
).execute(&pool.0).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
56
koucha/src/db/feed_item.rs
Normal file
56
koucha/src/db/feed_item.rs
Normal 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<()> {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
Result,
|
Result,
|
||||||
db::Channel,
|
db::{Channel, ChannelId},
|
||||||
AdapterClient,
|
AdapterClient,
|
||||||
};
|
};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue