Modulified it
This commit is contained in:
parent
22871f5789
commit
440e897edf
6 changed files with 296 additions and 195 deletions
49
koucha/src/feed.rs
Normal file
49
koucha/src/feed.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
Result,
|
||||
Item,
|
||||
Channel,
|
||||
channel::UnparsedChannel,
|
||||
};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
pub struct FeedId(pub i64);
|
||||
impl From<i64> for FeedId { fn from(id: i64) -> Self { FeedId(id) } }
|
||||
impl From<FeedId> for i64 { fn from(id: FeedId) -> Self { id.0 } }
|
||||
|
||||
pub struct Feed {
|
||||
pub id: FeedId,
|
||||
}
|
||||
|
||||
impl Feed {
|
||||
pub async fn get_items(
|
||||
pool: &SqlitePool, id: FeedId, limit: u8, offset: u32
|
||||
) -> Result<Vec<Item>> {
|
||||
let items = sqlx::query_as!(
|
||||
Item,
|
||||
"SELECT item_id as id FROM feed_items
|
||||
WHERE feed_id = ? AND archived = FALSE
|
||||
ORDER BY score DESC
|
||||
LIMIT ? OFFSET ?",
|
||||
id.0, limit, offset
|
||||
).fetch_all(pool).await?;
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
pub async fn get_channels(
|
||||
pool: &SqlitePool, id: FeedId
|
||||
) -> Result<Vec<Channel>> {
|
||||
let channels: Result<Vec<Channel>> = sqlx::query_as!(
|
||||
UnparsedChannel,
|
||||
"SELECT c.id as `id!`, c.title, c.link, c.description, c.last_fetched
|
||||
FROM channels c
|
||||
JOIN feed_channels fc on c.id = fc.channel_id
|
||||
WHERE fc.feed_id = ?",
|
||||
id.0
|
||||
).fetch_all(pool).await?.into_iter()
|
||||
.map(UnparsedChannel::parse).collect();
|
||||
|
||||
channels
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue