2024-05-25 16:11:52 +04:00
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
|
2024-05-25 16:51:34 +04:00
|
|
|
from repository import QuestionRepository
|
|
|
|
from schemas import SQuestionAdd, SQuestion, SQuestionId
|
2024-05-25 16:11:52 +04:00
|
|
|
|
|
|
|
router = APIRouter(
|
2024-05-25 16:51:34 +04:00
|
|
|
prefix="/questions",
|
|
|
|
tags=["Questions"],
|
2024-05-25 16:11:52 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
@router.post("")
|
2024-05-25 16:51:34 +04:00
|
|
|
async def add_question(
|
|
|
|
question: Annotated[SQuestionAdd, Depends()],
|
|
|
|
) -> SQuestionId:
|
|
|
|
question_id = await QuestionRepository.add_one(question)
|
|
|
|
return {"ok": True, "question_id": question_id}
|
2024-05-25 16:11:52 +04:00
|
|
|
|
|
|
|
@router.get("")
|
2024-05-25 16:51:34 +04:00
|
|
|
async def get_questions() -> list[SQuestion]:
|
|
|
|
questions = await QuestionRepository.find_all()
|
|
|
|
return questions
|