Files
test/app/schema/teacher_schema.py
T

61 lines
2.1 KiB
Python
Raw Normal View History

2026-09-21 19:03:31 +08:00
"""老师模块出入参(需求 2.5)。"""
from __future__ import annotations
from datetime import date
from pydantic import BaseModel, Field
from app.schema.common import GENDER_VALIDATOR, ORMBase, STRIP_VALIDATOR
class _TeacherBase(BaseModel):
name: str = Field(..., min_length=1, max_length=30, description="姓名")
gender: int = Field(1, description="性别 1=男 2=女")
phone: str | None = Field(None, max_length=20, description="手机号")
email: str | None = Field(None, max_length=60, description="邮箱")
title: str | None = Field(None, max_length=30, description="职称")
subject: str | None = Field(None, max_length=50, description="授课方向")
hire_date: str | None = Field(None, description="入职时间 YYYY-MM-DD")
remark: str | None = Field(None, max_length=255, description="备注")
_v_gender = GENDER_VALIDATOR
_v_strip = STRIP_VALIDATOR
class TeacherCreate(_TeacherBase):
teacher_no: str | None = Field(None, max_length=20, description="工号,不传自动生成 T+年份+序号")
class_ids: list[int] = Field(default_factory=list, description="带的班级ID列表")
class TeacherUpdate(BaseModel):
name: str | None = Field(None, min_length=1, max_length=30)
gender: int | None = None
phone: str | None = None
email: str | None = None
title: str | None = None
subject: str | None = None
hire_date: str | None = None
remark: str | None = None
class_ids: list[int] | None = Field(None, description="传了就整体替换带班关系")
_v_gender = GENDER_VALIDATOR
_v_strip = STRIP_VALIDATOR
class TeacherOut(ORMBase):
id: int
teacher_no: str = Field(..., description="工号")
name: str
gender: int
gender_text: str | None = None
phone: str | None = None
email: str | None = None
title: str | None = None
subject: str | None = None
hire_date: date | None = None
remark: str | None = None
class_ids: list[int] = Field(default_factory=list, description="带班ID")
class_names: list[str] = Field(default_factory=list, description="带班名称")
class_count: int = Field(0, description="带班数量")