Got the structure; got lots of tests; item still needs work
This commit is contained in:
parent
d7123fb153
commit
7bb4cf4230
5 changed files with 338 additions and 88 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{
|
||||
Result,
|
||||
Item,
|
||||
item::UnparsedItem,
|
||||
Channel,
|
||||
channel::{
|
||||
UnparsedChannel,
|
||||
|
|
@ -77,10 +78,11 @@ impl Feed {
|
|||
pub async fn add_channel(
|
||||
&self, pool: &SqlitePool, channel_id: ChannelId
|
||||
) -> Result<()> {
|
||||
let int_channel_id = i64::from(channel_id);
|
||||
sqlx::query!(
|
||||
"INSERT INTO feed_channels (feed_id, channel_id)
|
||||
VALUES (?, ?)",
|
||||
self.id.0, channel_id.0
|
||||
self.id.0, int_channel_id
|
||||
).execute(pool).await?;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -89,16 +91,16 @@ impl Feed {
|
|||
pub async fn get_items(
|
||||
&self, pool: &SqlitePool, limit: u8, offset: u32
|
||||
) -> Result<Vec<Item>> {
|
||||
let items = sqlx::query_as!(
|
||||
Item,
|
||||
let items: Result<Vec<Item>> = sqlx::query_as!(
|
||||
UnparsedItem,
|
||||
"SELECT item_id as id FROM feed_items
|
||||
WHERE feed_id = ? AND archived = FALSE
|
||||
ORDER BY score DESC
|
||||
LIMIT ? OFFSET ?",
|
||||
self.id.0, limit, offset
|
||||
).fetch_all(pool).await?;
|
||||
).fetch_all(pool).await?.into_iter().map(UnparsedItem::parse).collect();
|
||||
|
||||
Ok(items)
|
||||
items
|
||||
}
|
||||
|
||||
pub async fn get_channels(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue