Rewrote websocket
This commit is contained in:
parent
a791fc496e
commit
12a63e3523
13
run.bat
Normal file
13
run.bat
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
@echo off
|
||||||
|
cd %~dp0
|
||||||
|
|
||||||
|
if not exist "venv" (
|
||||||
|
echo Virtual environment not found.
|
||||||
|
echo Please run setup.py to create the virtual environment.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
call venv/Scripts/activate
|
||||||
|
python src/app.py
|
||||||
|
pause
|
48
setup.bat
Normal file
48
setup.bat
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
@echo off
|
||||||
|
python --version >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Python is not installed. Please install Python and ensure it's in your PATH.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
ping -n 1 www.google.com >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo No internet connection detected. Please connect to the internet and try again.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Installing virtual environment package...
|
||||||
|
python -m pip install virtualenv >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Failed to install virtualenv. Please check your Python installation or internet connection.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Creating virtual environment...
|
||||||
|
python -m venv venv
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Failed to create virtual environment. Please check your Python installation.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Activating virtual environment...
|
||||||
|
call venv\Scripts\activate.bat
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Failed to activate virtual environment. Please check your setup.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
python -m pip install -r requirements.txt
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Failed to install required packages. Please check requirements.txt or internet connection.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Setup completed successfully.
|
||||||
|
pause
|
@ -1,5 +1,5 @@
|
|||||||
from flask_jwt_extended import get_jwt_identity, jwt_required
|
from flask_jwt_extended import get_jwt_identity, jwt_required
|
||||||
from flask_socketio import emit
|
from flask_socketio import emit, join_room
|
||||||
|
|
||||||
from infra.server import socketio
|
from infra.server import socketio
|
||||||
from repos.reservation_repo import ReservationRepository
|
from repos.reservation_repo import ReservationRepository
|
||||||
@ -16,12 +16,21 @@ def handle_disconnect():
|
|||||||
print('Client disconnected')
|
print('Client disconnected')
|
||||||
|
|
||||||
@socketio.on('subscribe_reservations')
|
@socketio.on('subscribe_reservations')
|
||||||
#@jwt_required()
|
|
||||||
def handle_subscribe(data):
|
def handle_subscribe(data):
|
||||||
room_id = data.get('room_id')
|
room_id = data.get('room_id')
|
||||||
reservations = [] # ReservationRepository.list_all({'room_id': room_id})
|
date = data.get('date')
|
||||||
|
room = f"{room_id}_{date}"
|
||||||
|
join_room(room)
|
||||||
|
reservations = ReservationRepository.list_all({
|
||||||
|
'room_id': room_id,
|
||||||
|
'date': date
|
||||||
|
})
|
||||||
emit('reservations_update', reservations)
|
emit('reservations_update', reservations)
|
||||||
|
|
||||||
def notify_clients(room_id):
|
def notify_clients(room_id, date):
|
||||||
reservations = [] # ReservationRepository.list_all({'room_id': room_id})
|
room = f"{room_id}_{date}"
|
||||||
socketio.emit('reservations_update', reservations, room=room_id)
|
reservations = ReservationRepository.list_all({
|
||||||
|
'room_id': room_id,
|
||||||
|
'date': date
|
||||||
|
})
|
||||||
|
socketio.emit('reservations_update', reservations, room=room)
|
Loading…
x
Reference in New Issue
Block a user