add `/<uuid> route + backend handling
This commit is contained in:
29
src/model/client.rs
Normal file
29
src/model/client.rs
Normal 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user