This commit is contained in:
msj
2026-09-22 14:34:22 +08:00
parent 9e13a01c76
commit a4136ea648
4 changed files with 40 additions and 21 deletions
+12 -8
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter,Depends,HTTPException
from fastapi import APIRouter,HTTPException
from dao.student_dao import *
from schema.student_schema import *
from util.database import get_db
@@ -33,10 +33,10 @@ def update_students(s:StudentRequest
,db=Depends(get_db)):
d = s.model_dump(exclude_unset=True)
if not d:
raise HTTPException(status_code=400, detail='更新内容不能为空!')
raise HTTPException(status_code=400, detail='更新内容不能为空')
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
if not r:
raise HTTPException(status_code=500, detail='没有更新!')
raise HTTPException(status_code=500, detail='没有更新')
return {'code':200,'totals':r,'detail':'更新成功'}
@StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息删除接口',description='删除学生信息')
@@ -50,8 +50,12 @@ def del_students(stu_id:int
@StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
def add_students(s:StudentRequest
,db=Depends(get_db)):
d=s.model_dump(exclude_unset=True)
stu_new=add_student_dao(o=d,db=db)
if not stu_new:
raise HTTPException(status_code=404,detail='添加失败')
return stu_new
d = s.model_dump(exclude_unset=True)
if not d:
raise HTTPException(status_code=400, detail='添加内容不能为空')
r = add_student_dao( o=d, db=db)
if r == 'conflict':
raise HTTPException(status_code=409, detail='身份证号已存在,请勿重复添加')
if r == 'error':
raise HTTPException(status_code=500, detail='更添加失败,请稍后重试')
return r