Browse Source

Finally Fuel Person Task URAAA

main
Saruar 1 year ago
parent
commit
8555c7c445
4 changed files with 27 additions and 7 deletions
  1. BIN
      .DS_Store
  2. +7
    -3
      app/apis/v1/route_fuelingtask.py
  3. +6
    -1
      app/db/repository/fuelingtask.py
  4. +14
    -3
      app/schemas/fuelingtask.py

BIN
.DS_Store View File


+ 7
- 3
app/apis/v1/route_fuelingtask.py View File

@@ -6,7 +6,7 @@ from db.repository.fuelingtask import (
delete_fueling_task, delete_fueling_task,
get_fueling_task_by_id get_fueling_task_by_id
) )
from schemas.fuelingtask import CreateFuelingTask
from schemas.fuelingtask import CreateFuelingTask, OutputFuelingTask
from db.models.user import User from db.models.user import User
from apis.v1.route_auth import get_current_user from apis.v1.route_auth import get_current_user


@@ -40,7 +40,7 @@ def create_fuelingtask(






@router.get("/{fueling_task_id}", status_code=status.HTTP_200_OK)
@router.get("/{fueling_task_id}", response_model=OutputFuelingTask, status_code=status.HTTP_200_OK)
def get_fuelingtask( def get_fuelingtask(
fueling_task_id: int, fueling_task_id: int,
db: Session = Depends(get_db), db: Session = Depends(get_db),
@@ -50,8 +50,12 @@ def get_fuelingtask(
raise HTTPException( raise HTTPException(
status_code=403, detail="You are not authorized to perform this action" status_code=403, detail="You are not authorized to perform this action"
) )
fuelingtask = get_fueling_task_by_id(fueling_task_id, db) fuelingtask = get_fueling_task_by_id(fueling_task_id, db)
if fuelingtask == "notfound":
raise HTTPException(
status_code=404, detail="fuck off"
)
return fuelingtask return fuelingtask


@router.delete("/{fueling_task_id}", status_code=status.HTTP_204_NO_CONTENT) @router.delete("/{fueling_task_id}", status_code=status.HTTP_204_NO_CONTENT)


+ 6
- 1
app/db/repository/fuelingtask.py View File

@@ -44,6 +44,11 @@ def delete_fueling_task(fueling_task_id: int, db: Session):


def get_fueling_task_by_id(fuel_task_id: int, db: Session): def get_fueling_task_by_id(fuel_task_id: int, db: Session):
fuel_task = db.query(FuelingTask).filter(FuelingTask.Id == fuel_task_id).first() fuel_task = db.query(FuelingTask).filter(FuelingTask.Id == fuel_task_id).first()
if not fuel_task:
return "notfound"
res = fuel_task.__dict__ res = fuel_task.__dict__
res["Driver"] = get_user_by_id(fuel_task.DriverId, db=db)
driver = get_user_by_id(fuel_task.DriverId, role="Driver", db=db)
driver_obj = driver.__dict__
res["Driver"] = driver_obj
res["Driver"]["AssignedVehicle"] = driver.vehicle
return fuel_task return fuel_task

+ 14
- 3
app/schemas/fuelingtask.py View File

@@ -1,13 +1,24 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from datetime import datetime from datetime import datetime
from schemas.user import ShowDriver


class CreateFuelingTask(BaseModel): class CreateFuelingTask(BaseModel):
VehicleId: str = Field(...)
VehicleId: int = Field(...)
Description: str = Field(...)
Date: datetime = Field(...)
Cost: int = Field(...)
FuelRefilled: int = Field(...)
GasStationName: str = Field(...)
ImageBefore: str = Field(...)
ImageAfter: str = Field(...)

class OutputFuelingTask(BaseModel):
VehicleId: int = Field(...)
Description: str = Field(...) Description: str = Field(...)
Date: datetime = Field(...) Date: datetime = Field(...)
Cost: int = Field(...) Cost: int = Field(...)
FuelRefilled: int = Field(...) FuelRefilled: int = Field(...)
GasStationName: str = Field(...) GasStationName: str = Field(...)
ImageBefore: str = Field(...) ImageBefore: str = Field(...)
ImageAfter: str = Field(...)
ImageAfter: str = Field(...)
Driver: ShowDriver | None

Loading…
Cancel
Save