diff --git a/api/main.py b/api/main.py index c7e8e9c..75ab95e 100644 --- a/api/main.py +++ b/api/main.py @@ -34,7 +34,7 @@ class ConnectionManager: async def broadcast( self, - data: dict, + data: any, ): for connection in self.connections: asyncio.ensure_future(connection.send_json(data)) @@ -47,53 +47,34 @@ api = FastAPI( title=config.Main.app_name, ) -polls = [ +scripts = [ { 'id': 1, 'name': 'Текущее состояние сотрудников', - 'daysOfWeek': 'ПН-ПТ', - 'time': '11:00', - 'questionNumber': '1 вопрос', + 'time': '0 11 * * 1-5', + 'messageNumber': '1 вопрос', 'isEnabled': True, }, { 'id': 2, 'name': 'Планы на обед', - 'daysOfWeek': 'ПН-ПТ', - 'time': '11:45-12:00', - 'questionNumber': '2 вопроса', + 'time': '45 11 * * 1-5', + 'messageNumber': '2 вопроса', 'isEnabled': False, }, ] -@api.get( - path='/api/polls', -) -async def _(): - return polls - - -@api.put( - path='/api/polls', +@api.websocket( + path='/ws/scripts', ) async def _( - poll: dict, + websocket: WebSocket, ): - for i, p in enumerate(polls): - if p['id'] == poll['id']: - polls[i] = poll - - -# @app.websocket( -# path='/ws/sync', -# ) -# async def _( -# websocket: WebSocket, -# ): -# await connection_manager.connect(websocket) -# try: -# while True: -# await connection_manager.broadcast(await websocket.receive_json()) -# except WebSocketDisconnect: -# connection_manager.disconnect(websocket) + await connection_manager.connect(websocket) + try: + await connection_manager.broadcast(scripts) + while True: + await connection_manager.broadcast(await websocket.receive_json()) + except WebSocketDisconnect: + connection_manager.disconnect(websocket)