Pull out feed_channel, add more tests

This commit is contained in:
Julia Lange 2026-01-23 16:35:43 -08:00
parent 0bb9a81d60
commit 0639c5ca12
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto
4 changed files with 184 additions and 42 deletions

View file

@ -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,