PIbd-32_Kashin_M.I_API_Cour.../router.py

23 lines
599 B
Python
Raw Normal View History

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