feat: server can actually create root and sections
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
38
crates/hyperlog-server/src/services/create_root.rs
Normal file
38
crates/hyperlog-server/src/services/create_root.rs
Normal 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())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user