from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from app.api.dependencies.db import get_db from app.crud.model_path.early_start import model_path_early_start_dtr from app.schemas.model_path.early_start import ( EarlyStartDTRModelPath, EarlyStartDTRModelPathCreate, EarlyStartDTRModelPathUpdate, ) router = APIRouter() @router.post("/early-start/dtr", response_model=EarlyStartDTRModelPath) async def create_model_path( model_path: EarlyStartDTRModelPathCreate, db: Session = Depends(get_db) ): return model_path_early_start_dtr.create(db=db, obj_in=model_path) @router.get("/early-start/dtr", response_model=list[EarlyStartDTRModelPath]) async def read_model_path( skip: int = 0, limit: int = 100, db: Session = Depends(get_db) ): model_paths = model_path_early_start_dtr.get_multi(db, skip=skip, limit=limit) return model_paths @router.get("/early-start/dtr/{device_id}", response_model=EarlyStartDTRModelPath) async def read_model_path_by_device(device_id: str, db: Session = Depends(get_db)): db_model_path = model_path_early_start_dtr.get_path_by_device( db=db, device_id=device_id ) return db_model_path @router.put("/early-start/dtr/{device_id}", response_model=EarlyStartDTRModelPath) async def update_model_path( device_id: str, model_path_in: EarlyStartDTRModelPathUpdate, db: Session = Depends(get_db), ): model_path = model_path_early_start_dtr.get_path_by_device( db=db, device_id=device_id ) if model_path.device_id == device_id: new_model_path = model_path_early_start_dtr.update( db=db, db_obj=model_path, obj_in=model_path_in ) else: raise HTTPException(status_code=404, detail="Model path not found") return new_model_path @router.delete("/early-start/dtr/{id}", response_model=EarlyStartDTRModelPath) async def delete_model_path(id: int, db: Session = Depends(get_db)): model_path = model_path_early_start_dtr.get(db=db, id=id) if not model_path: raise HTTPException(status_code=404, detail="Model path not found") model_path = model_path_early_start_dtr.remove(db=db, id=id) return model_path