summaryrefslogtreecommitdiff
path: root/src/index/app.rs
blob: 79f5a9a52996f9e97e1f380003b604fc4f3186e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use sqlx::sqlite::SqlitePool;

use crate::{
    channel::repo::{Channel, Provider as _},
    error::BoxedError,
};

pub struct Index<'a> {
    db: &'a SqlitePool,
}

impl<'a> Index<'a> {
    pub fn new(db: &'a SqlitePool) -> Self {
        Self { db }
    }

    pub async fn for_authenticated(&self) -> Result<Vec<Channel>, BoxedError> {
        let mut tx = self.db.begin().await?;
        let channels = tx.channels().all().await?;
        tx.commit().await?;

        Ok(channels)
    }
}