simple Log In endpoint without encryption

This commit is contained in:
2025-09-22 23:58:07 +02:00
parent 3450c216c0
commit 007071cf12
14 changed files with 680 additions and 60 deletions

View File

@@ -6,30 +6,38 @@ use r2d2_sqlite::SqliteConnectionManager;
type HotelId = i32; // or i32 if you want numeric ids
#[derive(Clone)]
pub struct HotelPools {
pools: Arc<DashMap<HotelId, Pool<SqliteConnectionManager>>>,
pub struct AppState {
pub hotel_pools: HotelPool,
pub logs_pool: Pool<SqliteConnectionManager>,
pub jwt_secret: String
}
impl HotelPools {
#[derive(Clone)]
pub struct HotelPool {
hotel_pools: Arc<DashMap<HotelId, Pool<SqliteConnectionManager>>>,
}
impl HotelPool {
pub fn new() -> Self {
Self {
pools: Arc::new(DashMap::new()),
hotel_pools: Arc::new(DashMap::new()),
}
}
pub fn get_pool(&self, hotel_id: i32) -> Pool<SqliteConnectionManager> {
if let Some(pool) = self.pools.get(&hotel_id) {
if let Some(pool) = self.hotel_pools.get(&hotel_id) {
return pool.clone();
}
let db_path = format!("db/{}.sqlite", hotel_id);
let manager = SqliteConnectionManager::file(db_path);
let pool = Pool::builder()
let hotels_manager = SqliteConnectionManager::file(db_path);
let db_pool = Pool::builder()
.max_size(5) // adjust based on load
.build(manager)
.build(hotels_manager)
.expect("Failed to build pool");
self.pools.insert(hotel_id, pool.clone());
pool
self.hotel_pools.insert(hotel_id, db_pool.clone());
db_pool
}
}