37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
from fastapi import APIRouter,Depends,HTTPException
|
|
from Teachers.schema import *
|
|
from Teachers.database import *
|
|
from Teachers.model.tea_model import *
|
|
from Teachers.dao.tea_dao import *
|
|
from Teachers.schema.tea_request import TeaRequest
|
|
from Teachers.schema.tea_response import TeaResponse
|
|
|
|
tea_api = APIRouter(tags=['老师相关接口'])
|
|
|
|
@tea_api.post('/tea',response_model=TeaResponse)
|
|
def add_tea(tea: TeaRequest,db=Depends(get_db)):
|
|
r = add_tea_dao(tea.model_dump(),db)
|
|
if not r:
|
|
raise HTTPException(status_code=500,detail='添加失败!')
|
|
return TeaResponse(totals=1,date=tea.model_dump())
|
|
@tea_api.get('/tea',response_model=TeaResponse)
|
|
def get_tea(t:TeaRequest,db=Depends(get_db)): #开启会话窗口
|
|
r = get_tea_dao(t,db=db)
|
|
if not r:
|
|
raise HTTPException(status_code=404,detail='老师不存在')
|
|
return TeaResponse(totals=len(r),date=r)
|
|
@tea_api.delete('tea/{id}')
|
|
def delete_tea(id:int|None,db=Depends(get_db)):
|
|
r = delete_tea_dao(id,db)
|
|
if not r:
|
|
raise HTTPException(status_code=500,detail='删除失败!')
|
|
return {'detail':'删除成功!'}
|
|
|
|
@tea_api.put('tea/{id}')
|
|
def update_tea(id:int,tea:TeaRequest,db=Depends(get_db)):
|
|
t = tea.model_dump(exclude_unset= True)
|
|
r = update_tea_dao(id=id,update_data=t,db=db)
|
|
if not r:
|
|
raise HTTPException(status_code=404,detail='老师不存在')
|
|
return {'detail':'修改成功'}
|