nb
This commit is contained in:
@@ -6,11 +6,11 @@ from schema.grade_schema import *
|
||||
|
||||
gradeAPI = APIRouter(tags=['学生考核成绩'])
|
||||
|
||||
@gradeAPI.get("/grade/{stu_id}",summary="根据学生id查询成绩")
|
||||
@gradeAPI.get("/grade/{stu_id}",response_model=list[GradeResponse],summary="根据学生id查询成绩")
|
||||
def get_grade(stu_id: int,db=Depends(get_db)):
|
||||
try:
|
||||
res=get_grade_dao(stu_id,db)
|
||||
return {'code': 200,'msg':'查询成功','data':res}
|
||||
return res
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
||||
|
||||
@@ -23,13 +23,13 @@ def post_grade(o:GradeRequest=Form(),db=Depends(get_db)):
|
||||
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)
|
||||
def put_grade(score_id: int,o:GradeRequest=Form(),db=Depends(get_db)):
|
||||
d = o.model_dump(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='没有更新')
|
||||
if not d:
|
||||
raise HTTPException(status_code=500,detail='请传入需要修改的字段')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@gradeAPI.delete('/{score_id}',summary='删除成绩')
|
||||
|
||||
@@ -9,6 +9,7 @@ def get_grade_dao( stu_id:int , db):
|
||||
|
||||
r1 =db.query(WlScore).filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0).all()
|
||||
if r1:
|
||||
|
||||
return r1
|
||||
else:
|
||||
raise HTTPException(status_code=404,detail="学生不存在")
|
||||
@@ -21,15 +22,15 @@ def add_grade_dao(g,db):
|
||||
return o1
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return None
|
||||
raise HTTPException(status_code=500,detail="学生添加失败")
|
||||
|
||||
def update_grade_dao(score_id:int, update_data, db):
|
||||
try:
|
||||
rows = db.query(WlScore).filter(
|
||||
WlScore.stu_id == score_id,
|
||||
WlScore.score_id == score_id,
|
||||
WlScore.delete_status == 0
|
||||
).update(update_data)
|
||||
except:
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
|
||||
@@ -4,17 +4,15 @@ from fastapi import HTTPException
|
||||
|
||||
|
||||
class GradeRequest(BaseModel):
|
||||
stu_id:str|None = Field(description="学生编号")
|
||||
stu_id:int = Field(description="学生编号")
|
||||
exam_order:int = Field(description='考核序次')
|
||||
score:float = Field(description='成绩')
|
||||
|
||||
class GradeUpdate(BaseModel):#修改请求体
|
||||
exam_order: int = Field(description='考核序次')
|
||||
score: float = Field(description='成绩')
|
||||
|
||||
class GradeResponse(BaseModel):
|
||||
code: int = 200
|
||||
detail: str = 'OK'
|
||||
stu_id:str
|
||||
stu_id:int
|
||||
exam_order:int
|
||||
score:float
|
||||
score:float
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user