add ws root url
This commit is contained in:
parent
3d2ddbd695
commit
1ecfe5daab
@ -16,6 +16,7 @@ from sqlmodel import Session, select
|
||||
|
||||
import config
|
||||
import routes.base
|
||||
import routes.room.routes
|
||||
from database.auth.crud import create_user_db
|
||||
from database.auth.models import User, UserRead
|
||||
from database.db import create_db_and_tables, get_session
|
||||
@ -140,9 +141,8 @@ def check_if_token_in_denylist(decrypted_token):
|
||||
'''
|
||||
|
||||
#ROUTES
|
||||
|
||||
app.include_router(routes.base.api_router)
|
||||
|
||||
app.include_router(routes.room.routes.ws_router)
|
||||
|
||||
@app.delete('/access-revoke')
|
||||
def access_revoke(Authorize: AuthJWT = Depends()):
|
||||
|
@ -73,8 +73,6 @@ async def get_parcours_route(*, parcours: Parcours = Depends(get_parcours), memb
|
||||
return serialize_parcours(parcours, member, db)
|
||||
|
||||
|
||||
|
||||
|
||||
@router.put('/room/{room_id}/parcours/{parcours_id}', response_model=ParcoursRead)
|
||||
async def update_parcours(*, room_id: str, parcours: ParcoursCreate, member: Member = Depends(check_admin),
|
||||
parcours_old: Parcours = Depends(get_parcours), m: RoomManager = Depends(get_manager),
|
||||
@ -90,13 +88,16 @@ async def update_parcours(*, room_id: str, parcours: ParcoursCreate, member: Mem
|
||||
await m.broadcast({"type": "edit_parcours", "data": {
|
||||
"parcours": ParcoursReadUpdate(**parcours_obj.dict(), update_challenges=update_challenges).dict()}},
|
||||
parcours_old.id_code)
|
||||
|
||||
|
||||
await m.broadcast(
|
||||
lambda m: {"type": "update_challenges", "data": {"challenger": {"id_code": m.id_code, "name": getUsername(m), "validated": getMemberValidated(m, parcours_obj, db)},
|
||||
lambda m: {"type": "update_challenges", "data": {"challenger": {"id_code": m.id_code, "name": getUsername(m),
|
||||
"validated": getMemberValidated(m, parcours_obj,
|
||||
db)},
|
||||
"challenges": [Challenges(
|
||||
**{**chall.dict(), "canCorrige": chall.data != []}).dict() for
|
||||
chall in
|
||||
getMemberChallenges(m, parcours_obj, db)]}},
|
||||
**{**chall.dict(), "canCorrige": chall.data != []}).dict()
|
||||
for
|
||||
chall in
|
||||
getMemberChallenges(m, parcours_obj, db)]}},
|
||||
parcours_old.id_code, conditions=[lambda m: m.member.id_code != member.id_code])
|
||||
|
||||
return serialize_parcours(parcours_obj, member, db)
|
||||
@ -118,7 +119,6 @@ class Exos(BaseModel):
|
||||
@router.get('/room/{room_id}/challenge/{parcours_id}')
|
||||
def challenge_route(parcours: Parcours = Depends(get_parcours), exercices: List[Exos] = Depends(get_exercices),
|
||||
member: Member = Depends(get_member_dep), db: Session = Depends(get_session)):
|
||||
|
||||
correction = [parseGeneratorOut(generate_from_path(add_fast_api_root(
|
||||
e['exercice'].exo_source), e['quantity'], "web")) for e in exercices]
|
||||
|
||||
@ -161,21 +161,20 @@ async def send_challenge(*, challenge: List[CorrectionData], correction: TmpCorr
|
||||
await m.broadcast(lambda m: {"type": "newRanks", "data": {"rank": getMemberRank(m, correction.parcours, db),
|
||||
"avgRank": getMemberAvgRank(m, correction.parcours, db)}},
|
||||
parcours.id_code)
|
||||
|
||||
|
||||
await m.send_to(parcours.room.id_code, member.id_code, {"type": "parcours_stats", "data": {
|
||||
"parcours": ParcoursReadShort(name=parcours.name, best_note=challenger.best, validated=challenger.validated,
|
||||
id_code=parcours.id_code, avg=challenger.avg).dict()}})
|
||||
|
||||
|
||||
rank, avgRank = getRank(
|
||||
challenger, parcours, db), getAvgRank(challenger, parcours, db)
|
||||
|
||||
|
||||
if rank <= 3 or avgRank <= 3:
|
||||
await m.broadcast({"type": "newTops", "data": {
|
||||
"tops": getTops(correction.parcours, db),
|
||||
"avgTops": getAvgTops(correction.parcours, db),
|
||||
}}, parcours.id_code)
|
||||
|
||||
|
||||
db.delete(correction)
|
||||
returnValue = {**chall.dict()}
|
||||
db.commit()
|
||||
@ -249,7 +248,10 @@ async def corrige(*, correction: List[CorrigedData] = Body(), challenge: Challen
|
||||
# return {**ChallengeRead.from_orm(challenge).dict(), "challenger": {"name": obj.username, }}
|
||||
|
||||
|
||||
@router.websocket('/ws/room/{room_id}')
|
||||
ws_router = APIRouter(tags=["room"])
|
||||
|
||||
|
||||
@ws_router.websocket('/ws/room/{room_id}')
|
||||
async def room_ws(ws: WebSocket, room: Room | None = Depends(check_room), db: Session = Depends(get_session),
|
||||
m: RoomManager = Depends(get_manager)):
|
||||
consumer = RoomConsumer(ws=ws, room=room, manager=m, db=db)
|
||||
|
@ -27,7 +27,7 @@
|
||||
const room = writable<Room | null>(null);
|
||||
const member = writable<Member | null>(null);
|
||||
const parcours = writable<ParcoursRead | null>(null);
|
||||
const ws = connect(`${env.PUBLIC_API_BASE.replace("https", "ws").replace('http', "ws")}ws/room/${$page.params.slug}`);
|
||||
const ws = connect(`${env.PUBLIC_WS_BASE}room/${$page.params.slug}`);
|
||||
|
||||
setContext("room", room);
|
||||
setContext("member", member);
|
||||
|
Loading…
x
Reference in New Issue
Block a user