1
This commit is contained in:
@@ -6,7 +6,7 @@ from util.database import get_db
|
||||
|
||||
StudentAPI = APIRouter(tags=['学生基本信息管理模块'])
|
||||
|
||||
@StudentAPI.get('/students',response_model=StudentPageResponse,summary='学生信息查询接口',description='查询学生信息')
|
||||
@StudentAPI.get('/students',response_model=StuPageResponse,summary='学生信息查询接口',description='查询学生信息')
|
||||
def get_students(stu_id:int|None=None
|
||||
,stu_name:str|None=None
|
||||
,class_id:int|None=None
|
||||
@@ -19,39 +19,11 @@ def get_students(stu_id:int|None=None
|
||||
,page=page
|
||||
,page_size=page_size
|
||||
,db=db)
|
||||
|
||||
if not r:
|
||||
raise HTTPException(status_code=404,detail='学生不存在')
|
||||
return StudentPageResponse(page=page,
|
||||
page_size=page_size,
|
||||
totals=total,
|
||||
data=r)
|
||||
|
||||
@StudentAPI.put('/{stu_id}',summary='学生信息更新接口',description='更新学生信息')
|
||||
def update_students(s:StudentRequest
|
||||
,stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
d = s.model_dump(exclude_unset=True)
|
||||
d.pop('stu_id', None)
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='更新内容不能为空')
|
||||
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
||||
if r == 'conflict':
|
||||
raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用')
|
||||
if r == 'error':
|
||||
raise HTTPException(status_code=500, detail='更新失败,请稍后重试')
|
||||
if not r:
|
||||
raise HTTPException(status_code=404, detail='没有更新')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/{stu_id}',summary='学生信息删除接口',description='删除学生信息')
|
||||
def del_students(stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||
if not rows:
|
||||
raise HTTPException(status_code=404,detail='对象已被删除')
|
||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||
|
||||
@StudentAPI.post('/students',response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
||||
def add_students(s:StudentRequest
|
||||
,db=Depends(get_db)):
|
||||
@@ -62,5 +34,30 @@ def add_students(s:StudentRequest
|
||||
if r == 'conflict':
|
||||
raise HTTPException(status_code=409, detail='身份证号已存在,请勿重复添加')
|
||||
if r == 'error':
|
||||
raise HTTPException(status_code=500, detail='更添加失败,请稍后重试')
|
||||
raise HTTPException(status_code=500, detail='添加失败,请稍后重试')
|
||||
return r
|
||||
|
||||
@StudentAPI.put('/students/{stu_id}',summary='学生信息更新接口',description='更新学生信息')
|
||||
def update_students(stu_id:int
|
||||
,s:StuUpdateRequest
|
||||
,db=Depends(get_db)):
|
||||
d = s.model_dump(exclude_unset=True)
|
||||
d.pop('stu_id', None)
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='更新内容不能为空')
|
||||
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
||||
if r == 'conflict':
|
||||
raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用')
|
||||
if r == 'error':
|
||||
raise HTTPException(status_code=500, detail='更新失败,请稍后重试')
|
||||
if not r:
|
||||
raise HTTPException(status_code=404, detail='学生不存在或已被删除,更新失败')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/students/{stu_id}',response_model= StugetResponse,summary='学生信息删除接口',description='删除学生信息')
|
||||
def del_students(stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||
if not rows:
|
||||
raise HTTPException(status_code=404,detail='学生不存在或已被删除')
|
||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||
|
||||
Reference in New Issue
Block a user