add `/<uuid> route + backend handling

This commit is contained in:
2025-08-02 19:11:39 +02:00
parent 9badb4a4ad
commit 96a9ab361a
10 changed files with 116 additions and 50 deletions

29
src/model/client.rs Normal file
View File

@@ -0,0 +1,29 @@
use crate::Backend;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
#[derive(FromRow, Debug, Serialize, Deserialize)]
pub struct Client {
pub uuid: String,
pub name: Option<String>,
}
impl Backend {
pub(crate) async fn get_client(&self, uuid: &Uuid) -> Client {
let uuid = uuid.to_string();
match self {
Backend::Sqlite(db) => {
sqlx::query!("INSERT OR IGNORE INTO client (uuid) VALUES (?);", uuid)
.execute(db)
.await
.unwrap();
sqlx::query_as!(Client, "SELECT uuid, name FROM client WHERE uuid = ?", uuid)
.fetch_one(db)
.await
.expect("we assured that uuid exists in previous query")
}
}
}
}