48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
![]() |
use std::sync::Arc;
|
||
|
|
||
|
use axum::{
|
||
|
Json,
|
||
|
extract::{State, Query},
|
||
|
response::IntoResponse,
|
||
|
http::StatusCode
|
||
|
};
|
||
|
use serde::Deserialize;
|
||
|
use bb8::Pool;
|
||
|
use bb8_postgres::PostgresConnectionManager;
|
||
|
use tokio_postgres::NoTls;
|
||
|
|
||
|
use crate::minecraft_session::create_profile_response;
|
||
|
|
||
|
|
||
|
|
||
|
#[derive(Deserialize)]
|
||
|
pub struct ProfileQuery {
|
||
|
uuid: String,
|
||
|
}
|
||
|
|
||
|
pub async fn profile(
|
||
|
State(pool): State<Arc<Pool<PostgresConnectionManager<NoTls>>>>,
|
||
|
Query(params): Query<ProfileQuery>,
|
||
|
) -> impl IntoResponse {
|
||
|
let conn = match pool.get().await {
|
||
|
Ok(conn) => conn,
|
||
|
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, Json(serde_json::json!({
|
||
|
"error": "InternalServerError",
|
||
|
"errorMessage": "Failed to get DB connection"
|
||
|
}))).into_response()
|
||
|
};
|
||
|
|
||
|
let query = "SELECT username FROM accounts WHERE uuid = $1";
|
||
|
let row = match conn.query_one(query, &[¶ms.uuid]).await {
|
||
|
Ok(row) => row,
|
||
|
Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({
|
||
|
"error": "NotFound",
|
||
|
"errorMessage": "User not found"
|
||
|
}))).into_response()
|
||
|
};
|
||
|
|
||
|
let username: String = row.get("username");
|
||
|
|
||
|
create_profile_response(params.uuid, username)
|
||
|
}
|