get hotel endpoint
This commit is contained in:
BIN
db/1.sqlite
BIN
db/1.sqlite
Binary file not shown.
BIN
db/1.sqlite-shm
BIN
db/1.sqlite-shm
Binary file not shown.
BIN
db/1.sqlite-wal
BIN
db/1.sqlite-wal
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,12 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use axum::{
|
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::extract::TypedHeader;
|
||||||
//use axum_extra::TypedHeader;
|
//use axum_extra::TypedHeader;
|
||||||
|
|
||||||
|
use futures_util::future::TrySelect;
|
||||||
use headers::{UserAgent, Cookie};
|
use headers::{UserAgent, Cookie};
|
||||||
|
|
||||||
use axum::extract::FromRef;
|
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) {
|
fn internal_error<E: std::fmt::Display>(err: E) -> (StatusCode, String) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ pub fn utils_routes() -> Router<AppState> {
|
|||||||
.route("/register", put(register_user))
|
.route("/register", put(register_user))
|
||||||
|
|
||||||
.route("/tokentest", put(token_tester))
|
.route("/tokentest", put(token_tester))
|
||||||
.route("/force_update_password", put(force_update_password))
|
|
||||||
.route("/update_password", put(update_password))
|
.route("/update_password", put(update_password))
|
||||||
|
|
||||||
.route("/create_refresh", post(create_refresh_token))
|
.route("/create_refresh", post(create_refresh_token))
|
||||||
@@ -26,8 +25,12 @@ pub fn utils_routes() -> Router<AppState> {
|
|||||||
|
|
||||||
.route("/logout_single_device", post(logout_from_single_device))
|
.route("/logout_single_device", post(logout_from_single_device))
|
||||||
.route("/logout_all_devices", post(logout_from_all_devices))
|
.route("/logout_all_devices", post(logout_from_all_devices))
|
||||||
|
|
||||||
.route("/ws/{req_token}", get(ws_handler))
|
.route("/ws/{req_token}", get(ws_handler))
|
||||||
|
|
||||||
|
.route("/force_update_password", put(force_update_password))
|
||||||
|
.route("/get_hotels", get(get_hotel))
|
||||||
|
|
||||||
|
|
||||||
//.with_state(state)
|
//.with_state(state)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user