move cmd off of grpc

This commit is contained in:
2025-12-30 14:19:41 -05:00
parent 29f7f6d83b
commit 6980b7f6aa
26 changed files with 452 additions and 389 deletions

View File

@@ -1,9 +1,9 @@
pub mod panel;
use crate::core::Uuid;
use crate::panels::panel::{PanelRequired, PanelUpdate};
use panel::Panel;
use sqlx::SqlitePool;
use uuid::Uuid;
pub struct PanelService {
pool: SqlitePool,
@@ -15,7 +15,8 @@ impl PanelService {
}
pub async fn create(&self, name: &str, data: &str) -> anyhow::Result<Uuid> {
let id = Uuid::random();
let id = Uuid::new_v4();
let id_string = id.to_string();
let mut transaction = self.pool.begin().await?;
@@ -24,7 +25,7 @@ impl PanelService {
INSERT INTO PANELS (id, name, data, deleted)
VALUES ($1, $2, $3, FALSE);
"#,
id.value,
id_string,
name,
data
)
@@ -65,7 +66,7 @@ impl PanelService {
WHERE id = $1 AND deleted = FALSE
"#,
)
.bind(id.value)
.bind(id.to_string())
.fetch_optional(&mut *transaction)
.await?;
@@ -75,6 +76,7 @@ impl PanelService {
}
pub async fn update(&self, id: Uuid, data: PanelUpdate) -> anyhow::Result<()> {
let id = id.to_string();
let mut transaction = self.pool.begin().await?;
if let Some(name) = data.name {
@@ -84,7 +86,7 @@ impl PanelService {
SET name = $2
WHERE id = $1;
"#,
id.value,
id,
name
)
.execute(&mut *transaction)
@@ -97,7 +99,7 @@ impl PanelService {
SET data = $2
WHERE id = $1;
"#,
id.value,
id,
data
)
.execute(&mut *transaction)
@@ -110,6 +112,7 @@ impl PanelService {
}
pub async fn delete(&self, id: Uuid) -> anyhow::Result<()> {
let id = id.to_string();
let mut transaction = self.pool.begin().await?;
let _ = sqlx::query!(
@@ -118,7 +121,7 @@ impl PanelService {
SET deleted = TRUE
WHERE id = $1;
"#,
id.value,
id,
)
.execute(&mut *transaction)
.await?;