Skip to content

Commit

Permalink
add filtering parameters to GET /quizzes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jfredrickson committed Apr 10, 2023
1 parent 5fe5c0a commit ae33872
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions training/api/api_v1/quizzes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ def create_quiz(quiz: QuizCreate, repo: QuizRepository = Depends(quiz_repository


@router.get("/quizzes", response_model=List[QuizPublic])
def get_quizzes(repo: QuizRepository = Depends(quiz_repository)):
return repo.find_all()
def get_quizzes(
topic: str | None = None,
audience: str | None = None,
active: bool | None = None,
repo: QuizRepository = Depends(quiz_repository)
):
filters = {}
if topic is not None:
filters["topic"] = topic
if audience is not None:
filters["audience"] = audience
if active is not None:
filters["active"] = active
return repo.find_all(filters=filters)


@router.get("/quizzes/{id}", response_model=QuizPublic)
Expand Down

0 comments on commit ae33872

Please sign in to comment.