split frontend and backend to initialize tauri frontend

This commit is contained in:
2025-12-15 13:42:55 +01:00
parent 30f4155369
commit 43a55a9a7c
11 changed files with 3637 additions and 0 deletions

25
src/db.rs Normal file
View File

@@ -0,0 +1,25 @@
use axum::http::StatusCode;
use sqlx::PgPool;
use uuid::Uuid;
pub async fn init_db() -> Result<PgPool, sqlx::Error> {
let database_url = "postgres://chatapp:secret@localhost:5432/chatapp";
PgPool::connect(database_url).await
}
pub async fn user_id_from_uuid(db: &PgPool, user_uuid: Uuid) -> Result<i32, (StatusCode, String)> {
sqlx::query_scalar("SELECT id FROM user_ WHERE uuid = $1")
.bind(user_uuid)
.fetch_one(db)
.await
.map_err(|_| (StatusCode::UNAUTHORIZED, String::from("Wrong token")))
}
pub async fn room_id_from_uuid(db: &PgPool, room_uuid: Uuid) -> Result<i32, (StatusCode, String)> {
sqlx::query_scalar("SELECT id FROM room_ WHERE uuid = $1")
.bind(room_uuid)
.fetch_one(db)
.await
// FIX: hmm probably the wrong error here
.map_err(|_| (StatusCode::UNAUTHORIZED, String::from("Wrong token")))
}