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

26 lines
531 B
Python

from typing import Annotated
from fastapi import APIRouter, Depends
from repository import TaskRepository
from schemas import STaskAdd, STask, STaskId
router = APIRouter(
prefix="/tasks",
tags=["Таски"],
)
@router.post("")
async def add_task(
task: Annotated[STaskAdd, Depends()],
) -> STaskId:
task_id = await TaskRepository.add_one(task)
return {"ok": True, "task_id": task_id}
@router.get("")
async def get_tasks() -> list[STask]:
tasks = await TaskRepository.find_all()
return tasks