Pull out feed_channel, add more tests
This commit is contained in:
parent
0bb9a81d60
commit
0639c5ca12
4 changed files with 184 additions and 42 deletions
|
|
@ -6,7 +6,8 @@ use crate::{
|
|||
db::{
|
||||
ChannelId,
|
||||
Item,
|
||||
FeedId,
|
||||
FeedChannel,
|
||||
feed_channel::UnparsedFeedChannel,
|
||||
item::UnparsedItem,
|
||||
},
|
||||
fetch::FetchedRSSChannel,
|
||||
|
|
@ -34,40 +35,6 @@ impl UnparsedChannel {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct UnparsedFeedChannel {
|
||||
pub channel_id: i64,
|
||||
pub feed_id: i64,
|
||||
}
|
||||
impl UnparsedFeedChannel {
|
||||
pub fn parse(self) -> Result<FeedChannel> {
|
||||
Ok(FeedChannel {
|
||||
channel_id: ChannelId(self.channel_id),
|
||||
feed_id: FeedId(self.feed_id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FeedChannel {
|
||||
channel_id: ChannelId,
|
||||
feed_id: FeedId,
|
||||
}
|
||||
|
||||
impl FeedChannel {
|
||||
pub async fn add_item(
|
||||
&self, pool: &AdapterPool, item: &Item
|
||||
) -> Result<()> {
|
||||
let int_item_id = i64::from(item.id());
|
||||
let int_feed_id = i64::from(self.feed_id);
|
||||
|
||||
sqlx::query!(
|
||||
"INSERT OR IGNORE INTO feed_items (feed_id, item_id, score)
|
||||
VALUES (?, ?, 5)", // TODO: Add in scoring featuress
|
||||
int_feed_id, int_item_id
|
||||
).execute(&pool.0).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Channel {
|
||||
id: ChannelId,
|
||||
title: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue