wip
This commit is contained in:
parent
83313f6cd4
commit
5101d4c478
5 changed files with 35 additions and 16 deletions
|
|
@ -82,4 +82,4 @@ async def get_heros(
|
|||
session: Session = Depends(get_session),
|
||||
) -> list[Hero]:
|
||||
"get all heros"
|
||||
return HeroRead.list(session=session)
|
||||
return Heros.list(session=session)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
||||
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlmodel import Session
|
||||
|
||||
from learn_sql_model.api.websocket_connection_manager import manager
|
||||
from learn_sql_model.config import get_session
|
||||
from learn_sql_model.models.hero import Heros
|
||||
|
||||
web_socket_router = APIRouter()
|
||||
|
||||
|
|
@ -70,3 +73,14 @@ async def websocket_endpoint(websocket: WebSocket):
|
|||
except WebSocketDisconnect:
|
||||
manager.disconnect(websocket, id)
|
||||
await manager.broadcast(f"Client #{id} left the chat", id)
|
||||
|
||||
|
||||
@web_socket_router.websocket("/wsecho")
|
||||
async def websocket_endpoint(
|
||||
websocket: WebSocket,
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
await websocket.accept()
|
||||
while True:
|
||||
heros = Heros.list(session=session)
|
||||
await websocket.send_text(heros.json())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue