websocket for single db update

This commit is contained in:
2025-09-26 04:05:22 +02:00
parent 65146fce91
commit a3b55f00df
6 changed files with 38 additions and 23 deletions

View File

@@ -5,19 +5,18 @@ use r2d2_sqlite::SqliteConnectionManager;
use tokio::sync::mpsc;
use axum::extract::{ws::{Message, WebSocket, WebSocketUpgrade}, State};
use crate::utils::websocket::WsMap;
#[derive(Clone)]
pub struct AppState {
pub hotel_pools: HotelPool,
pub logs_pool: Pool<SqliteConnectionManager>,
pub ws_map: WsMap,
}
type HotelId = i32; // or i32 if you want numeric ids
#[derive(Clone)]
pub struct AppState {
pub hotel_pools: HotelPool,
pub logs_pool: Pool<SqliteConnectionManager>,
pub ws_map: WsMap,
}
#[derive(Clone)]
pub struct HotelPool {
hotel_pools: Arc<DashMap<HotelId, Pool<SqliteConnectionManager>>>,

View File

@@ -12,11 +12,11 @@ use crate::utils::{auth::AuthClaims, db_pool::{AppState, HotelPool}};
/// Type alias: user_id → sender to that user
type UserMap = DashMap<i32, mpsc::UnboundedSender<Message>>;
pub type UserMap = DashMap<i32, mpsc::UnboundedSender<Message>>;
/// hotel_id → users
type HotelMap = DashMap<i32, Arc<UserMap>>;
pub type HotelMap = DashMap<i32, Arc<UserMap>>;
/// global map of all hotels
type WsMap = Arc<HotelMap>;
pub type WsMap = Arc<HotelMap>;
/// Type alias: user_id → sender to that user