選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

33 行
974 B

  1. from fastapi import Depends, APIRouter
  2. from sqlalchemy.orm import Session
  3. from fastapi import status, HTTPException
  4. from typing import Annotated
  5. from db.session import get_db
  6. from core.config import settings
  7. from db.repository.drivetask import (
  8. create_new_task,
  9. )
  10. from schemas.drivetask import CreateTask
  11. from db.models.user import User
  12. from apis.v1.route_auth import get_current_user
  13. router = APIRouter()
  14. @router.post("/", status_code=status.HTTP_201_CREATED)
  15. def create_tasK(
  16. task: CreateTask,
  17. db: Session = Depends(get_db),
  18. current_user: User = Depends(get_current_user),
  19. ):
  20. if current_user.Role != "Admin":
  21. raise HTTPException(
  22. status_code=403, detail="You are not authorized to perform this action"
  23. )
  24. task_res = create_new_task(task=task, db=db)
  25. if task_res == "notdriver":
  26. raise HTTPException(
  27. status_code=404, detail=f"Driver with id {task.DriverId} not found"
  28. )
  29. return task