✨ Finished game-results
This commit is contained in:
@@ -13,20 +13,14 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[GameResults])
|
||||
async def list_game_results(include_quiz: bool = False, user: User = Depends(get_current_user)):
|
||||
if include_quiz is True:
|
||||
results = await GameResults.objects.select_related("quiz").all(user=user.id)
|
||||
else:
|
||||
results = await GameResults.objects.all(user=user.id)
|
||||
async def list_game_results(user: User = Depends(get_current_user)):
|
||||
results = await GameResults.objects.all(user=user.id)
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/list/{quiz_id}", response_model=list[GameResults])
|
||||
async def get_results_by_quiz(quiz_id: UUID, include_quiz: bool = False, user: User = Depends(get_current_user)):
|
||||
if include_quiz is True:
|
||||
res = await GameResults.objects.select_related("quiz").all(user=user.id, quiz=quiz_id)
|
||||
else:
|
||||
res = await GameResults.objects.all(user=user.id, quiz=quiz_id)
|
||||
async def get_results_by_quiz(quiz_id: UUID, user: User = Depends(get_current_user)):
|
||||
res = await GameResults.objects.all(user=user.id, quiz=quiz_id)
|
||||
if res is None:
|
||||
raise HTTPException(status_code=404, detail="Game Result not found")
|
||||
else:
|
||||
@@ -34,11 +28,8 @@ async def get_results_by_quiz(quiz_id: UUID, include_quiz: bool = False, user: U
|
||||
|
||||
|
||||
@router.get("/{game_id}", response_model=GameResults)
|
||||
async def get_game_result(game_id: UUID, include_quiz: bool = False, user: User = Depends(get_current_user)):
|
||||
if include_quiz:
|
||||
res = await GameResults.objects.select_related("quiz").get_or_none(user=user.id, id=game_id)
|
||||
else:
|
||||
res = await GameResults.objects.get_or_none(user=user.id, id=game_id)
|
||||
async def get_game_result(game_id: UUID, user: User = Depends(get_current_user)):
|
||||
res = await GameResults.objects.get_or_none(user=user.id, id=game_id)
|
||||
if res is None:
|
||||
raise HTTPException(status_code=404, detail="Game Result not found")
|
||||
else:
|
||||
@@ -56,3 +47,29 @@ async def set_note(id: UUID, data: _SetNoteInput, user: User = Depends(get_curre
|
||||
raise HTTPException(status_code=404, detail="Game Result not found")
|
||||
res.note = data.note
|
||||
return await res.update()
|
||||
|
||||
|
||||
"""
|
||||
@router.get("/export/{result_id}", response_class=StreamingResponse)
|
||||
async def export_result(result_id: UUID, user: User = Depends(get_current_user)):
|
||||
res = await GameResults.objects.get_or_none(user=user.id, id=result_id)
|
||||
if res is None:
|
||||
raise HTTPException(status_code=404, detail="Game Result not found")
|
||||
quiz = Quiz(title=res.title, questions=res.questions)
|
||||
spreadsheet = await generate_spreadsheet(
|
||||
quiz=quiz, quiz_results=data, player_fields=player_fields, player_scores=score_data
|
||||
)
|
||||
|
||||
def iter_file():
|
||||
yield from spreadsheet
|
||||
|
||||
return StreamingResponse(
|
||||
iter_file(),
|
||||
media_type="application/vnd.ms-excel",
|
||||
headers={
|
||||
"Content-Disposition": f"attachment;filename=ClassQuiz-{urllib.parse.quote(quiz.title)}-{datetime.strftime('%m-%d-%Y')}.xlsx"
|
||||
# noqa: E501
|
||||
},
|
||||
)
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user