diff --git a/db/1.sqlite b/db/1.sqlite index 913c080..5366c39 100644 Binary files a/db/1.sqlite and b/db/1.sqlite differ diff --git a/db/1.sqlite-shm b/db/1.sqlite-shm index 73b6945..fe9ac28 100644 Binary files a/db/1.sqlite-shm and b/db/1.sqlite-shm differ diff --git a/db/1.sqlite-wal b/db/1.sqlite-wal index b997f51..e69de29 100644 Binary files a/db/1.sqlite-wal and b/db/1.sqlite-wal differ diff --git a/db/auth_copy_2.sqlite-shm b/db/auth_copy_2.sqlite-shm index 147ae44..14ec0b1 100644 Binary files a/db/auth_copy_2.sqlite-shm and b/db/auth_copy_2.sqlite-shm differ diff --git a/src/utils/auth.rs b/src/utils/auth.rs index 20947c3..90aa563 100644 --- a/src/utils/auth.rs +++ b/src/utils/auth.rs @@ -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 + +)-> 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 = match hotel_itter.collect::, _>>() { + 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(err: E) -> (StatusCode, String) { diff --git a/src/utils/routes.rs b/src/utils/routes.rs index bd0c748..a1774c6 100644 --- a/src/utils/routes.rs +++ b/src/utils/routes.rs @@ -18,7 +18,6 @@ pub fn utils_routes() -> Router { .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)) @@ -26,8 +25,12 @@ pub fn utils_routes() -> Router { .route("/logout_single_device", post(logout_from_single_device)) .route("/logout_all_devices", post(logout_from_all_devices)) - + .route("/ws/{req_token}", get(ws_handler)) + + .route("/force_update_password", put(force_update_password)) + .route("/get_hotels", get(get_hotel)) + //.with_state(state) } \ No newline at end of file