nb
This commit is contained in:
@@ -14,17 +14,27 @@ def get_grade(stu_id: int,db=Depends(get_db)):
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
||||
|
||||
@gradeAPI.post('/{stu_id}',response_model=GradeResponse,summary='添加学生成绩')
|
||||
@gradeAPI.post('/grade',response_model=GradeResponse,summary='添加学生成绩')
|
||||
def post_grade(o:GradeRequest=Form(),db=Depends(get_db)):
|
||||
|
||||
exist_obj = get_grade_dao(db,o.stu_id)
|
||||
if exist_obj:
|
||||
raise HTTPException(status_code=409, detail="该学生此考核序次成绩已存在!")
|
||||
|
||||
d=o.model_dump()
|
||||
r=add_grade_dao(g=d,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=400, detail='学生不存在')
|
||||
return o
|
||||
|
||||
@gradeAPI.put('/{score_id}',summary='成绩修改')
|
||||
def put_grade(score_id: int,o:GradeUpdate,db=Depends(get_db)):
|
||||
d = o.model_update(exclude_unset=True)
|
||||
r = update_grade_dao(score_id=score_id
|
||||
,update_data=d
|
||||
,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=500,detail='没有更新')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@gradeAPI.delete('/{score_id}',summary='删除成绩')
|
||||
def delete_grade(score_id:int,db=Depends(get_db)):
|
||||
r = delete_grade_dao(stu_id=score_id,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=404,detail='删除失败')
|
||||
return {'code':200,'totals':r,'detail':'删除成功'}
|
||||
Reference in New Issue
Block a user