split frontend and backend to initialize tauri frontend
This commit is contained in:
25
src/db.rs
Normal file
25
src/db.rs
Normal 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")))
|
||||
}
|
||||
Reference in New Issue
Block a user