test三轮完成的版本,并入了国伟的班级模块
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from dao.wl_score_dao import get_score, create_score, update_score, delete_score, list_score_by_stu_id
|
||||
from database import get_db
|
||||
|
||||
router = APIRouter(tags=["成绩CRUD"])
|
||||
|
||||
# 新增成绩
|
||||
@router.post("/score/add")
|
||||
def api_add_score(stu_id: int, exam_order: int, score: float, db: Session = Depends(get_db)):
|
||||
res = create_score(db, stu_id, exam_order, score)
|
||||
if res is None:
|
||||
raise HTTPException(status_code=400, detail="新增失败:学生不存在或成绩重复")
|
||||
return res
|
||||
|
||||
# 查询单条成绩
|
||||
@router.get("/score/one")
|
||||
def api_get_score(stu_id: int, exam_order: int, db: Session = Depends(get_db)):
|
||||
s = get_score(db, stu_id, exam_order)
|
||||
if not s:
|
||||
raise HTTPException(status_code=404, detail="成绩记录不存在")
|
||||
return s
|
||||
|
||||
# 查询某个学生全部成绩
|
||||
@router.get("/score/list/{stu_id}")
|
||||
def api_list_score(stu_id: int, db: Session = Depends(get_db)):
|
||||
return list_score_by_stu_id(db, stu_id)
|
||||
|
||||
# 更新成绩
|
||||
@router.put("/score/update")
|
||||
def api_update_score(stu_id: int, exam_order: int, new_score: float, db: Session = Depends(get_db)):
|
||||
obj = update_score(db, stu_id, exam_order, new_score)
|
||||
if obj is None:
|
||||
raise HTTPException(status_code=404, detail="更新失败,记录不存在")
|
||||
return obj
|
||||
|
||||
# 删除成绩
|
||||
@router.delete("/score/del")
|
||||
def api_del_score(stu_id: int, exam_order: int, db: Session = Depends(get_db)):
|
||||
ok = delete_score(db, stu_id, exam_order)
|
||||
if not ok:
|
||||
raise HTTPException(status_code=404, detail="删除失败,记录不存在")
|
||||
return {"msg": "删除成功"}
|
||||
Reference in New Issue
Block a user