Files
stu_teacher/scheme/scores.py
T

47 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# scheme/scores.py
# 成绩模块的请求/响应模型(含 60 分红线预警标记)
from typing import List, Optional
from pydantic import BaseModel, Field, field_validator
# -------------------- 请求体模型 -----------------------------
class ScoreAdd(BaseModel):
"""录入成绩:一个学生同一考核序次只有一条成绩(复合主键)"""
stu_id: int = Field(..., ge=1, description="学生编号")
exam_id: int = Field(..., ge=1, description="考核序次")
score: float = Field(..., ge=0, le=100, description="成绩(0-100)")
class ScoreUpdate(BaseModel):
score: float = Field(..., ge=0, le=100, description="新成绩(0-100)")
class ScoreDelete(BaseModel):
"""删除指定学生的某次成绩(需求 4.2 用 POST /score/delete 风格)"""
stu_id: int = Field(..., ge=1, description="学生编号")
exam_id: int = Field(..., ge=1, description="考核序次")
# -------------------- 响应模型 ----------------------------
class ScoreResponse(BaseModel):
stu_id: int
exam_id: int
score: float
stu_name: Optional[str] = Field(None, description="冗余展示:学生姓名")
is_warning: bool = Field(False, description="红线预警:成绩 < 60 为 True")
class Config:
from_attributes = True
class ScoreListResponse(BaseModel):
total: int
items: List[ScoreResponse]
class ScoreAddResponse(BaseModel):
"""录入成绩响应:附带预警提示(需求 2.2 可选扩展)"""
score: ScoreResponse
warning: Optional[str] = Field(None, description="成绩低于60分时的预警提示")