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 config
|
||||||
import routes.base
|
import routes.base
|
||||||
|
import routes.room.routes
|
||||||
from database.auth.crud import create_user_db
|
from database.auth.crud import create_user_db
|
||||||
from database.auth.models import User, UserRead
|
from database.auth.models import User, UserRead
|
||||||
from database.db import create_db_and_tables, get_session
|
from database.db import create_db_and_tables, get_session
|
||||||
@ -140,9 +141,8 @@ def check_if_token_in_denylist(decrypted_token):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
#ROUTES
|
#ROUTES
|
||||||
|
|
||||||
app.include_router(routes.base.api_router)
|
app.include_router(routes.base.api_router)
|
||||||
|
app.include_router(routes.room.routes.ws_router)
|
||||||
|
|
||||||
@app.delete('/access-revoke')
|
@app.delete('/access-revoke')
|
||||||
def access_revoke(Authorize: AuthJWT = Depends()):
|
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)
|
return serialize_parcours(parcours, member, db)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.put('/room/{room_id}/parcours/{parcours_id}', response_model=ParcoursRead)
|
@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),
|
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),
|
parcours_old: Parcours = Depends(get_parcours), m: RoomManager = Depends(get_manager),
|
||||||
@ -92,9 +90,12 @@ async def update_parcours(*, room_id: str, parcours: ParcoursCreate, member: Mem
|
|||||||
parcours_old.id_code)
|
parcours_old.id_code)
|
||||||
|
|
||||||
await m.broadcast(
|
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(
|
"challenges": [Challenges(
|
||||||
**{**chall.dict(), "canCorrige": chall.data != []}).dict() for
|
**{**chall.dict(), "canCorrige": chall.data != []}).dict()
|
||||||
|
for
|
||||||
chall in
|
chall in
|
||||||
getMemberChallenges(m, parcours_obj, db)]}},
|
getMemberChallenges(m, parcours_obj, db)]}},
|
||||||
parcours_old.id_code, conditions=[lambda m: m.member.id_code != member.id_code])
|
parcours_old.id_code, conditions=[lambda m: m.member.id_code != member.id_code])
|
||||||
@ -118,7 +119,6 @@ class Exos(BaseModel):
|
|||||||
@router.get('/room/{room_id}/challenge/{parcours_id}')
|
@router.get('/room/{room_id}/challenge/{parcours_id}')
|
||||||
def challenge_route(parcours: Parcours = Depends(get_parcours), exercices: List[Exos] = Depends(get_exercices),
|
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)):
|
member: Member = Depends(get_member_dep), db: Session = Depends(get_session)):
|
||||||
|
|
||||||
correction = [parseGeneratorOut(generate_from_path(add_fast_api_root(
|
correction = [parseGeneratorOut(generate_from_path(add_fast_api_root(
|
||||||
e['exercice'].exo_source), e['quantity'], "web")) for e in exercices]
|
e['exercice'].exo_source), e['quantity'], "web")) for e in exercices]
|
||||||
|
|
||||||
@ -166,7 +166,6 @@ async def send_challenge(*, challenge: List[CorrectionData], correction: TmpCorr
|
|||||||
"parcours": ParcoursReadShort(name=parcours.name, best_note=challenger.best, validated=challenger.validated,
|
"parcours": ParcoursReadShort(name=parcours.name, best_note=challenger.best, validated=challenger.validated,
|
||||||
id_code=parcours.id_code, avg=challenger.avg).dict()}})
|
id_code=parcours.id_code, avg=challenger.avg).dict()}})
|
||||||
|
|
||||||
|
|
||||||
rank, avgRank = getRank(
|
rank, avgRank = getRank(
|
||||||
challenger, parcours, db), getAvgRank(challenger, parcours, db)
|
challenger, parcours, db), getAvgRank(challenger, parcours, db)
|
||||||
|
|
||||||
@ -249,7 +248,10 @@ async def corrige(*, correction: List[CorrigedData] = Body(), challenge: Challen
|
|||||||
# return {**ChallengeRead.from_orm(challenge).dict(), "challenger": {"name": obj.username, }}
|
# 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),
|
async def room_ws(ws: WebSocket, room: Room | None = Depends(check_room), db: Session = Depends(get_session),
|
||||||
m: RoomManager = Depends(get_manager)):
|
m: RoomManager = Depends(get_manager)):
|
||||||
consumer = RoomConsumer(ws=ws, room=room, manager=m, db=db)
|
consumer = RoomConsumer(ws=ws, room=room, manager=m, db=db)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
const room = writable<Room | null>(null);
|
const room = writable<Room | null>(null);
|
||||||
const member = writable<Member | null>(null);
|
const member = writable<Member | null>(null);
|
||||||
const parcours = writable<ParcoursRead | 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("room", room);
|
||||||
setContext("member", member);
|
setContext("member", member);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user