36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# api/scores.py
|
|
# 本文件定义成绩相关的所有 API 路由
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from database import get_db
|
|
from dao.score_dao import ScoreDAO
|
|
from scheme.scores import ScoreUpdate, ScoreResponse
|
|
# 创建路由器,前缀将在 main.py 中统一添加
|
|
router = APIRouter()
|
|
# 根据 学号 + 考核次数 查询单条成绩
|
|
@router.get("/score/{sid}/{exam_num}", response_model=ScoreResponse)
|
|
async def get_score(
|
|
sid: int,
|
|
exam_num: int,
|
|
db: Session = Depends(get_db) # 依赖注入获得数据库会话
|
|
):
|
|
return ScoreDAO.get_by_id(db, sid, exam_num)
|
|
# 根据 学号 + 考核次数 修改成绩
|
|
@router.put("/score/update", response_model=ScoreResponse)
|
|
async def update_score(
|
|
sid: int,
|
|
exam_num: int,
|
|
score_data: ScoreUpdate,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
return ScoreDAO.update(db, sid, exam_num, score_data)
|
|
# 删除成绩,逻辑删除flag改为0
|
|
@router.post("/score/delete", response_model=ScoreResponse)
|
|
async def delete_score(
|
|
sid: int,
|
|
exam_num: int,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
return ScoreDAO.delete(db, sid, exam_num)
|