get hotel endpoint

This commit is contained in:
2026-01-19 19:15:44 +01:00
parent bd20d9728f
commit 52c4a31f9f
6 changed files with 73 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,11 +1,12 @@
use std::time::Duration;
use axum::{
body::{to_bytes, Body}, extract::{Extension, FromRequest, FromRequestParts, Path, State}, http::{header::{HeaderValue, SET_COOKIE}, request::Parts, Request as HttpRequest, StatusCode }, middleware::Next, response::{IntoResponse, IntoResponseParts, Response}, Json
Json, body::{Body, to_bytes}, extract::{Extension, FromRequest, FromRequestParts, Path, State}, http::{Request as HttpRequest, StatusCode, header::{HeaderValue, SET_COOKIE}, request::Parts, status }, middleware::Next, response::{IntoResponse, IntoResponseParts, Response}
};
use axum_extra::extract::TypedHeader;
//use axum_extra::TypedHeader;
use futures_util::future::TrySelect;
use headers::{UserAgent, Cookie};
use axum::extract::FromRef;
@@ -839,6 +840,72 @@ pub async fn logout_from_all_devices (
}
#[derive(Serialize)]
struct HotelData {
id: i32,
hotel_name: String,
}
pub async fn get_hotel(
State(state): State<AppState>
)-> impl IntoResponse {
let try_conn = state.logs_pool.get();
let conn = match try_conn {
Ok(conn)=> conn,
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, "bruh").into_response()
};
let try_stmt = conn.prepare("
SELECT id, hotelname
FROM hotels");
let mut stmt = match try_stmt {
Ok(stmt) =>stmt ,
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR,
"failed buildin statement")
.into_response()
};
let try_hotels = stmt.query_map(params![],
|row| {
Ok(HotelData {
id: row.get(0)?,
hotel_name: row.get(1)?,
})
}
);
let hotel_itter = match try_hotels {
Ok(hotels) => hotels,
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR,
"error processing hotel list")
.into_response()
};
let hotels: Vec<HotelData> = match hotel_itter.collect::<Result<Vec<_>, _>>() {
Ok(hotel) => hotel,
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR,
format!("failed collection of hotel : {e}"))
.into_response()
};
match serde_json::to_string(&hotels) {
Ok(json)=> return (StatusCode::OK, json).into_response(),
Err(e) => return (StatusCode::INTERNAL_SERVER_ERROR, format!("Serialization failed: {}", e)).into_response()
};
//.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB connection error".to_string()))?;
//return (StatusCode::OK).into_response();
}
fn internal_error<E: std::fmt::Display>(err: E) -> (StatusCode, String) {

View File

@@ -18,7 +18,6 @@ pub fn utils_routes() -> Router<AppState> {
.route("/register", put(register_user))
.route("/tokentest", put(token_tester))
.route("/force_update_password", put(force_update_password))
.route("/update_password", put(update_password))
.route("/create_refresh", post(create_refresh_token))
@@ -29,5 +28,9 @@ pub fn utils_routes() -> Router<AppState> {
.route("/ws/{req_token}", get(ws_handler))
.route("/force_update_password", put(force_update_password))
.route("/get_hotels", get(get_hotel))
//.with_state(state)
}