Skip to content

Commit bdf92c2

Browse files
committed
added time column to participant crud
1 parent 7cb2b52 commit bdf92c2

File tree

3 files changed

+25
-40
lines changed

3 files changed

+25
-40
lines changed

app/api/endpoints/quizEntry.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
tags=["Quiz"],
1313
)
1414

15-
@router.post("/join", response_model=List[quizEntry_schema.Question])
15+
@router.post("/join", response_model=quizEntry_schema.Question)
1616
async def add_participant(participant:quizEntry_schema.Participant ):
1717
return quiz_crud.join_quiz(participant)
1818

@@ -24,32 +24,6 @@ async def submit_answer(answer: quizEntry_schema.UpdateScore):
2424

2525
@router.post("/addQuestions", response_model=quizEntry_schema.RoomKey)
2626
async def add_question(request: quizEntry_schema.AddQuestionsRequest):
27-
return quiz_crud.add_questions(request.questions, request.user_id)
28-
29-
# @router.websocket("/ws/{room_key}")
30-
# async def websocket_endpoint(websocket: WebSocket, room_key: int):
31-
# await manager.connect(websocket, room_key)
32-
# try:
33-
# while True:
34-
# await websocket.receive_text() # Keep connection alive
35-
# except WebSocketDisconnect:
36-
# manager.disconnect(websocket, room_key)
37-
38-
39-
# @router.post("/broadcast-message/")
40-
# async def broadcast_message(room_key: int, message: str):
41-
# await manager.broadcast(f"{room_key}", json.dumps({"type": "announcement", "message": message}))
42-
# return {"message": "Broadcast sent"}
43-
44-
# @router.post("/startQuiz")
45-
# async def create_quiz(room_key: int, host_id: int):
46-
# response = supabase.table("leaderboard").insert({
47-
# "room_key": room_key,
48-
# "id": host_id
49-
# }).execute()
50-
51-
# if response.error:
52-
# raise HTTPException(status_code=400, detail=response.error.message)
53-
54-
# return {"message": "Quiz created successfully", "room_key": room_key}
27+
return quiz_crud.add_questions(request.questions, request.user_id, request.time)
28+
5529

app/crud/quiz_crud.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@ def join_quiz(participant: quizEntry_schema.Participant):
2323
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to register participant: {e}")
2424

2525
# Fetch quiz questions
26-
questions = supabase.table("questions").select("question", "answers", "correct_answer").eq("room_key", participant.room_key).execute()
26+
questions = supabase.table("questions").select("question", "answers", "correct_answer", "time").eq("room_key", participant.room_key).execute()
2727
if not questions.data:
2828
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="No questions found for the quiz")
2929

30+
response = [quizEntry_schema.questionResponse(
31+
question=question["question"],
32+
answers=question["answers"]["answers"],
33+
correct_answer=question["correct_answer"],
34+
time=question["time"]
35+
) for question in questions.data]
36+
3037
# Return list of questions
31-
return [quizEntry_schema.Question(
38+
return quizEntry_schema.Question(
3239
id=result.data[0]["id"],
3340
room_key=participant.room_key,
34-
question=question["question"],
35-
answers=question["answers"]["answers"],
36-
correct_answer=question["correct_answer"]
37-
) for question in questions.data]
41+
questions=response
42+
)
3843

3944
except Exception as e:
4045
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to join quiz: {e}")
@@ -76,7 +81,7 @@ def create_room(host_id: int):
7681
except Exception as e:
7782
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to create room: {e}")
7883

79-
def add_questions(questions: List[quizEntry_schema.AddQuestion], user_id: int):
84+
def add_questions(questions: List[quizEntry_schema.AddQuestion], user_id: int, time: int):
8085
try:
8186
# create a new room
8287
room_key = create_room(user_id)["room_key"]
@@ -90,7 +95,8 @@ def add_questions(questions: List[quizEntry_schema.AddQuestion], user_id: int):
9095
"room_key": room_key,
9196
"question": question.question,
9297
"answers": answers_json,
93-
"correct_answer": question.correct_answer
98+
"correct_answer": question.correct_answer,
99+
"time": time
94100
}).execute()
95101

96102
print("Questions added successfully")

app/schemas/quizEntry_schema.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ class AnswerSubmission(BaseModel):
1010
user_id: int
1111
score: int
1212

13-
class Question(BaseModel):
14-
id: int
15-
room_key: int
13+
class questionResponse(BaseModel):
1614
question: str
1715
answers: list
1816
correct_answer: str
17+
time: int
18+
19+
class Question(BaseModel):
20+
id: int
21+
room_key: int
22+
questions: List[questionResponse]
1923

2024
class AddQuestion(BaseModel):
2125
question: str
@@ -24,6 +28,7 @@ class AddQuestion(BaseModel):
2428

2529
class AddQuestionsRequest(BaseModel):
2630
user_id: int
31+
time: int
2732
questions: List[AddQuestion]
2833

2934
class RoomKey(BaseModel):

0 commit comments

Comments
 (0)