|
|
@@ -0,0 +1,32 @@ |
|
|
|
from fastapi import Depends, APIRouter |
|
|
|
from sqlalchemy.orm import Session |
|
|
|
from fastapi import status, HTTPException |
|
|
|
from typing import Annotated |
|
|
|
from db.session import get_db |
|
|
|
from core.config import settings |
|
|
|
from db.repository.drivetask import ( |
|
|
|
create_new_task, |
|
|
|
) |
|
|
|
from schemas.drivetask import CreateTask |
|
|
|
from db.models.user import User |
|
|
|
from apis.v1.route_auth import get_current_user |
|
|
|
|
|
|
|
router = APIRouter() |
|
|
|
|
|
|
|
|
|
|
|
@router.post("/", status_code=status.HTTP_201_CREATED) |
|
|
|
def create_tasK( |
|
|
|
task: CreateTask, |
|
|
|
db: Session = Depends(get_db), |
|
|
|
current_user: User = Depends(get_current_user), |
|
|
|
): |
|
|
|
if current_user.Role != "Admin": |
|
|
|
raise HTTPException( |
|
|
|
status_code=403, detail="You are not authorized to perform this action" |
|
|
|
) |
|
|
|
task_res = create_new_task(task=task, db=db) |
|
|
|
if task_res == "notdriver": |
|
|
|
raise HTTPException( |
|
|
|
status_code=404, detail=f"Driver with id {task.DriverId} not found" |
|
|
|
) |
|
|
|
return task |