feat: server can actually create root and sections
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-05-13 22:57:20 +02:00
parent 76f1c87663
commit 699bac7159
12 changed files with 276 additions and 49 deletions

View File

@@ -0,0 +1,38 @@
use crate::state::SharedState;
#[derive(Clone)]
pub struct CreateRoot {
db: sqlx::PgPool,
}
pub struct Request {
pub root: String,
}
pub struct Response {}
impl CreateRoot {
pub fn new(db: sqlx::PgPool) -> Self {
Self { db }
}
pub async fn execute(&self, req: Request) -> anyhow::Result<Response> {
let root_id = uuid::Uuid::new_v4();
sqlx::query(r#"INSERT INTO roots (id, root_name) VALUES ($1, $2)"#)
.bind(root_id)
.bind(req.root)
.execute(&self.db)
.await?;
Ok(Response {})
}
}
pub trait CreateRootExt {
fn create_root_service(&self) -> CreateRoot;
}
impl CreateRootExt for SharedState {
fn create_root_service(&self) -> CreateRoot {
CreateRoot::new(self.db.clone())
}
}