simple Log In endpoint without encryption
This commit is contained in:
@@ -3,13 +3,15 @@ use axum::response::IntoResponse;
|
||||
use axum::http::StatusCode;
|
||||
|
||||
use crate::rooms::extractor::UpdateRoomPayload;
|
||||
use crate::utils::db_pool::*;
|
||||
|
||||
|
||||
use std::sync::Arc;
|
||||
use r2d2::{Pool};
|
||||
use r2d2_sqlite::SqliteConnectionManager;
|
||||
use dashmap::DashMap;
|
||||
use rusqlite::params;
|
||||
use crate::utils::db_pool::*;
|
||||
|
||||
|
||||
|
||||
pub async fn hello_rooms() -> String {
|
||||
@@ -29,14 +31,12 @@ pub async fn fake_room_update(
|
||||
}
|
||||
|
||||
pub async fn fake_db_update(
|
||||
|
||||
State(hotel_pools): State<HotelPools>,
|
||||
State(state): State<AppState>,
|
||||
Path(room_id): Path<i32>,
|
||||
UpdateRoomPayload(payload): UpdateRoomPayload,
|
||||
|
||||
) -> impl IntoResponse {
|
||||
|
||||
let pool = hotel_pools.get_pool(payload.hotel_id);
|
||||
let pool = state.hotel_pools.get_pool(payload.hotel_id);
|
||||
let conn = match pool.get() {
|
||||
Ok(conn) => conn,
|
||||
Err(err) => return (StatusCode::INTERNAL_SERVER_ERROR, format!("Pool error: {err}")),
|
||||
@@ -57,23 +57,9 @@ pub async fn fake_db_update(
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//fake db handler
|
||||
pub async fn update_room(UpdateRoomPayload(payload): UpdateRoom) -> impl IntoResponse {
|
||||
match fake_db_update(&payload.token, payload.room_id, &payload.status).await {
|
||||
Ok(msg) => msg,
|
||||
Err(err) => format!("Error: {}", err),
|
||||
}
|
||||
struct RoomRequest {
|
||||
item_id: i32,
|
||||
item_amount: i32,
|
||||
token: String,
|
||||
}
|
||||
|
||||
async fn fake_db_update(token: &str, room_id: i32, status: &str) -> Result<String, String> {
|
||||
// Pretend we check the token in the DB
|
||||
if token != "valid_token" {
|
||||
return Err("Invalid token".into());
|
||||
}
|
||||
|
||||
// Pretend we update the room status in the DB
|
||||
Ok(format!("Room {} updated to '{}'", room_id, status))
|
||||
}
|
||||
*/
|
||||
@@ -4,14 +4,18 @@ use axum::{
|
||||
};
|
||||
|
||||
use crate::rooms::handler::*;
|
||||
use crate::utils::db_pool::HotelPools;
|
||||
use crate::utils::db_pool::{
|
||||
HotelPool,
|
||||
AppState,
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ROOTS
|
||||
pub fn rooms_routes() -> Router<HotelPools> {
|
||||
pub fn rooms_routes() -> Router {
|
||||
|
||||
Router::new()
|
||||
.route("/", get(hello_rooms) )
|
||||
.route("/fakeUpdate/{room_id}", put(fake_room_update))
|
||||
.route("/fake_db_update/{room_id}", put(fake_db_update))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user