All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
52 lines
999 B
Rust
52 lines
999 B
Rust
use crate::state::SharedState;
|
|
|
|
#[derive(Clone)]
|
|
pub struct GetAvailableRoots {
|
|
db: sqlx::PgPool,
|
|
}
|
|
|
|
pub struct Request {}
|
|
pub struct Response {
|
|
pub roots: Vec<String>,
|
|
}
|
|
|
|
#[derive(sqlx::FromRow)]
|
|
pub struct Root {
|
|
root_name: String,
|
|
}
|
|
|
|
impl GetAvailableRoots {
|
|
pub fn new(db: sqlx::PgPool) -> Self {
|
|
Self { db }
|
|
}
|
|
|
|
pub async fn execute(&self, _req: Request) -> anyhow::Result<Response> {
|
|
let roots: Vec<Root> = sqlx::query_as(
|
|
r#"
|
|
SELECT
|
|
*
|
|
FROM
|
|
roots
|
|
LIMIT
|
|
100
|
|
"#,
|
|
)
|
|
.fetch_all(&self.db)
|
|
.await?;
|
|
|
|
Ok(Response {
|
|
roots: roots.into_iter().map(|i| i.root_name).collect(),
|
|
})
|
|
}
|
|
}
|
|
|
|
pub trait GetAvailableRootsExt {
|
|
fn get_available_roots_service(&self) -> GetAvailableRoots;
|
|
}
|
|
|
|
impl GetAvailableRootsExt for SharedState {
|
|
fn get_available_roots_service(&self) -> GetAvailableRoots {
|
|
GetAvailableRoots::new(self.db.clone())
|
|
}
|
|
}
|