2026-09-21 14:17:09 +08:00
|
|
|
from fastapi import APIRouter,Depends,HTTPException
|
|
|
|
|
from schemas.class_schema import *
|
|
|
|
|
from core.database import get_db
|
|
|
|
|
from dao.class_dao import *
|
|
|
|
|
|
|
|
|
|
classes_router = APIRouter()
|
|
|
|
|
|
|
|
|
|
@classes_router.post('/',response_model=ClassResponse)
|
|
|
|
|
def post_classes(classes:ClassCreate,db=Depends(get_db)):
|
|
|
|
|
c = classes.model_dump()
|
|
|
|
|
r = post_classes_dao( c , db )
|
|
|
|
|
if r :
|
|
|
|
|
return ClassResponse( total=1,data=c )
|
|
|
|
|
else :
|
|
|
|
|
raise HTTPException(status_code=500,detail='添加失败,服务器繁忙,请稍后添加!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classes_router.put('/{id}',response_model=ClassResponse)
|
|
|
|
|
def put_classes(id:int,classes:ClassUpdate,db=Depends(get_db)):
|
|
|
|
|
updates = classes.model_dump( exclude_unset=True )
|
|
|
|
|
r = update_classes_dao( id , db , updates )
|
|
|
|
|
if r :
|
|
|
|
|
return ClassResponse( total=1,data=updates )
|
|
|
|
|
else :
|
|
|
|
|
raise HTTPException(status_code=500, detail='更新失败,该班级已不存在或服务器繁忙,请稍后更新!')
|