Parcourir la source

Finally Fuel Person Task URAAA

main
Saruar il y a 1 an
Parent
révision
8555c7c445
4 fichiers modifiés avec 27 ajouts et 7 suppressions
  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 Voir le fichier


+ 7
- 3
app/apis/v1/route_fuelingtask.py Voir le fichier

@@ -6,7 +6,7 @@ from db.repository.fuelingtask import (
delete_fueling_task,
get_fueling_task_by_id
)
from schemas.fuelingtask import CreateFuelingTask
from schemas.fuelingtask import CreateFuelingTask, OutputFuelingTask
from db.models.user import 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(
fueling_task_id: int,
db: Session = Depends(get_db),
@@ -50,8 +50,12 @@ def get_fuelingtask(
raise HTTPException(
status_code=403, detail="You are not authorized to perform this action"
)
fuelingtask = get_fueling_task_by_id(fueling_task_id, db)
if fuelingtask == "notfound":
raise HTTPException(
status_code=404, detail="fuck off"
)
return fuelingtask

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


+ 6
- 1
app/db/repository/fuelingtask.py Voir le fichier

@@ -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):
fuel_task = db.query(FuelingTask).filter(FuelingTask.Id == fuel_task_id).first()
if not fuel_task:
return "notfound"
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

+ 14
- 3
app/schemas/fuelingtask.py Voir le fichier

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

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(...)
Date: datetime = Field(...)
Cost: int = Field(...)
FuelRefilled: int = Field(...)
GasStationName: str = Field(...)
ImageBefore: str = Field(...)
ImageAfter: str = Field(...)
ImageAfter: str = Field(...)
Driver: ShowDriver | None

Chargement…
Annuler
Enregistrer