58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
|
|
|
|
|
#增加类
|
|
class AddTeacher(BaseModel):
|
|
t_name:str= Field(...,min_length=1,max_length=20,description='老师姓名'),
|
|
t_gender:str=Field(...,min_length=1,max_length=10,description='性别')
|
|
t_phone:str=Field(...,max_length=15,description="手机号码最多15位")
|
|
t_subject:str=Field(...,min_length=1,max_length=50,description='教授科目')
|
|
t_created:str=Field(...,description='入职时间,格式为%Y-%m-%d')
|
|
|
|
@field_validator('t_created')
|
|
def j_t_created(cls,v:str):
|
|
try:
|
|
t_created_date=datetime.strptime(v,'%Y-%m-%d') #时间转字符串日期
|
|
except ValueError:
|
|
raise ValueError('时间格式错误,请按照yyyy-MM-dd格式输入')
|
|
|
|
if t_created_date.date() > datetime.now().date():
|
|
raise ValueError('入职时间不能大于未来时间')
|
|
return v
|
|
|
|
#删除类
|
|
class DeleteTeacher(BaseModel):
|
|
t_id:int=Field(...,gt=0,description='老师id'),
|
|
t_name:str=Field(...,min_length=1,max_length=20,description='老师姓名')
|
|
|
|
|
|
#修改类
|
|
class UpdateTeacher(BaseModel):
|
|
t_name: str = Field(..., min_length=1, max_length=20, description='老师姓名')
|
|
t_gender: str = Field(..., min_length=1, max_length=10, description='性别')
|
|
t_phone: str = Field(..., max_length=15, description="手机号码最多15位")
|
|
t_subject: str = Field(..., min_length=1, max_length=50, description='教授科目')
|
|
t_created: str = Field(..., description='入职时间,格式为%Y-%m-%d')
|
|
|
|
@field_validator('t_created')
|
|
def j_t_created(cls, v: str):
|
|
try:
|
|
t_created_date = datetime.strptime(v, '%Y-%m-%d') # 时间转字符串日期
|
|
except ValueError:
|
|
raise ValueError('时间格式错误,请按照yyyy-MM-dd格式输入')
|
|
|
|
if t_created_date.date() > datetime.now().date():
|
|
raise ValueError('入职时间不能大于未来时间')
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|