添加statistics tag
This commit is contained in:
+7
-6
@@ -1,7 +1,7 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_db
|
||||
from dao.score import post_score_dao, update_score_dao, get_score_dao, delete_score_dao, exist_student_exam_dao
|
||||
from dao.score import post_score_dao, update_score_dao, get_score_dao,delete_score_dao, exist_student_exam_dao
|
||||
from schemas.score import ScoreCreate, ScoreUpdate, ScorePageResp
|
||||
|
||||
scores_router = APIRouter(prefix="/scores", tags=["成绩接口"])
|
||||
@@ -12,14 +12,13 @@ def create_score(req: ScoreCreate, db: Session = Depends(get_db)):
|
||||
# 业务校验:联合唯一
|
||||
if exist_student_exam_dao(req.student_id, req.exam_seq, db):
|
||||
raise HTTPException(status_code=400, detail="该学生本次考试成绩已存在,不能重复录入")
|
||||
|
||||
ok = post_score_dao(req.model_dump(), db)
|
||||
if not ok:
|
||||
raise HTTPException(status_code=400, detail="新增成绩失败,请检查学生id是否存在")
|
||||
return {"msg": "新增成功"}
|
||||
|
||||
|
||||
@scores_router.get("", response_model=ScorePageResp, summary="查询成绩接口")
|
||||
@scores_router.get("", response_model=ScorePageResp, summary="个人成绩查询接口")
|
||||
def list_score(
|
||||
score_id: int|None=None,
|
||||
student_id: int |None=None,
|
||||
@@ -32,7 +31,9 @@ def list_score(
|
||||
return {"total": total, "data": data_list}
|
||||
|
||||
|
||||
@scores_router.put("/{score_id}", summary="更新成绩接口")
|
||||
|
||||
|
||||
@scores_router.put("{score_id}", summary="更新成绩接口")
|
||||
def modify_score(score_id: int, req: ScoreUpdate, db: Session = Depends(get_db)):
|
||||
update_dict = req.model_dump(exclude_unset=True)
|
||||
if not update_dict:
|
||||
@@ -43,9 +44,9 @@ def modify_score(score_id: int, req: ScoreUpdate, db: Session = Depends(get_db))
|
||||
return {"msg": "修改成功"}
|
||||
|
||||
|
||||
@scores_router.delete("/{score_id}", summary="删除成绩接口")
|
||||
@scores_router.delete("{score_id}", summary="删除成绩接口")
|
||||
def remove_score(score_id: int, db: Session = Depends(get_db)):
|
||||
ok = delete_score_dao(score_id, db)
|
||||
if not ok:
|
||||
raise HTTPException(status_code=400, detail="删除失败,记录不存在或已删除")
|
||||
return {"msg": "逻辑删除成功"}
|
||||
return {"msg": "逻辑删除成功"}
|
||||
Reference in New Issue
Block a user