aaa
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from typing import Optional, List
|
||||
from datetime import date
|
||||
|
||||
class ClassCreate(BaseModel):
|
||||
cid : int= Field(...,description="班级编号")
|
||||
class_name : str= Field(...,min_length=1, max_length=50, description="班级名称")
|
||||
start_time:date
|
||||
headteacher : str=Field(...,min_length=1, max_length=50,description="班主任")
|
||||
flag:int
|
||||
class ClassUpdate(BaseModel):
|
||||
class_name:Optional[str]=Field(None,min_length=1, max_length=50)
|
||||
start_time: Optional[date] = None
|
||||
headteacher: Optional[str] = Field(None, min_length=1, max_length=50)
|
||||
#响应体参数
|
||||
class ClassResponse(BaseModel):
|
||||
cid : int
|
||||
class_name : str
|
||||
start_time : date
|
||||
headteacher : str
|
||||
flag : int
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class ClassListResponse(BaseModel):
|
||||
total: int
|
||||
items: list[ClassResponse]
|
||||
@@ -0,0 +1,24 @@
|
||||
# scheme/scores.py
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
#录入成绩的请求体模型
|
||||
class ScoreCreate(BaseModel):
|
||||
sid: int = Field(..., description="学号")
|
||||
exam_num: int = Field(..., description="考核次数(第几次考试)")
|
||||
score: float = Field(..., description="分数")
|
||||
|
||||
|
||||
# sid、exam_num 作为路径参数在路由中单独传入,更新请求体参数中只放需要更新的字段
|
||||
class ScoreUpdate(BaseModel):
|
||||
score: Optional[float] = Field(None, description="分数")
|
||||
|
||||
# 响应体模型返回学号,考试次数,以及考核分数
|
||||
class ScoreResponse(BaseModel):
|
||||
# score_id: int
|
||||
sid: int
|
||||
exam_num: int
|
||||
score: float
|
||||
flag: int
|
||||
class Config:
|
||||
from_attributes = True # 支持 ORM 对象转换
|
||||
@@ -0,0 +1,59 @@
|
||||
# scheme/students.py
|
||||
# 本文件定义学生模块用到的 Pydantic 模型(接口的请求参数 / 响应格式)
|
||||
from typing import Optional,List
|
||||
from datetime import date
|
||||
io
|
||||
|
||||
from model.classes import Class
|
||||
|
||||
|
||||
# 创建学生的请求体模型
|
||||
class StudentCreate(BaseModel):
|
||||
cid: int = Field(..., description="班级编号")
|
||||
name: str = Field(..., description="姓名")
|
||||
address: str = Field(..., description="籍贯")
|
||||
school: str = Field(..., description="毕业院校")
|
||||
major: str = Field(..., description="专业")
|
||||
start_time: date = Field(..., description="入学时间")
|
||||
end_time: Optional[date] = Field(None, description="毕业时间,未毕业可以不传")
|
||||
education: str = Field(..., description="学历")
|
||||
consultant_id: int = Field(..., description="顾问编号")
|
||||
gender: str = Field(...,max_length=1, description="性别,男/女")
|
||||
age: int = Field(..., description="年龄")
|
||||
#
|
||||
# 更新学生的请求体模型
|
||||
class StudentUpdate(BaseModel):
|
||||
cid: Optional[int] = None
|
||||
name: Optional[str] = None
|
||||
address: Optional[str] = None
|
||||
# school: Optional[str] = None
|
||||
# major: Optional[str] = None
|
||||
|
||||
# education: Optional[str] = None
|
||||
# consultant_id: Optional[int] = None
|
||||
# gender: Optional[str] = None
|
||||
# age: Optional[int] = None
|
||||
|
||||
|
||||
# 响应模型
|
||||
class StudentResponse(BaseModel):
|
||||
sid: int
|
||||
cid: int
|
||||
name: str
|
||||
address: str
|
||||
school: str
|
||||
major: str
|
||||
start_time: date
|
||||
end_time: Optional[date] = None
|
||||
education: str
|
||||
consultant_id: int
|
||||
gender: str
|
||||
age: int
|
||||
flag: int
|
||||
class Config:
|
||||
from_attributes = True # 支持 ORM 对象直接转换
|
||||
|
||||
|
||||
class StudentListResponse(BaseModel):
|
||||
total: int
|
||||
items: list[StudentResponse]
|
||||
@@ -0,0 +1,37 @@
|
||||
# scheme/teachers.py
|
||||
# 本文件定义老师模块用到的 Pydantic 模型
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# 新增教师的请求体模型 ----------
|
||||
class TeacherCreate(BaseModel):
|
||||
teacher_name: str = Field(..., description="老师姓名")
|
||||
gender: Optional[str] = Field(None, description="性别")
|
||||
phone: Optional[str] = Field(None, min_length=11,description="联系电话")
|
||||
is_headteacher: int = Field(0, ge=0, le=1, description="1-班主任 0-任课老师")
|
||||
|
||||
|
||||
class TeacherUpdate(BaseModel):
|
||||
teacher_name: Optional[str] = None
|
||||
gender: Optional[str] = None
|
||||
phone: Optional[str] = Field(None,min_length=11,description="联系电话")
|
||||
is_headteacher: Optional[int] = Field(None, ge=0, le=1)
|
||||
|
||||
|
||||
# 响应体模型
|
||||
class TeacherResponse(BaseModel):
|
||||
teacher_id: int
|
||||
teacher_name: str
|
||||
gender: Optional[str] = None
|
||||
phone: Optional[str] = None
|
||||
is_headteacher: int
|
||||
# flag: int
|
||||
#响应模型读取 SQLAlchemy ORM 对象属性 的配置
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class TeacherListResponse(BaseModel):
|
||||
total: int
|
||||
items: list[TeacherResponse]
|
||||
@@ -0,0 +1,48 @@
|
||||
#这是学生就业管理系统的请求模型
|
||||
|
||||
from datetime import date
|
||||
|
||||
from fastapi import HTTPException
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator,ConfigDict
|
||||
|
||||
|
||||
class StudentWorkCreate(BaseModel):
|
||||
sid :int = Field(...,ge=0,le=10000,description="输入0-10000之间的学生编号")
|
||||
open_time:date = Field(...,description="要写如下格式YYYY-MM-DD ")
|
||||
offer_time:date = Field(...,description="要写如下格式YYYY-MM-DD ")
|
||||
company_name: str = Field(...,max_length=50,description="公司名字")
|
||||
salary :float = Field(...,ge=0.1,le=10000.0,description="月薪")
|
||||
|
||||
@model_validator(mode="after")
|
||||
def time_available(self):
|
||||
if self.open_time>self.offer_time:
|
||||
raise HTTPException(status_code=422,detail="就业时间必须大于offer下发时间")
|
||||
return self
|
||||
class StudentWorkCreate1(BaseModel):
|
||||
sid :int = Field(...,ge=0,le=10000,description="输入0-10000之间的学生编号")
|
||||
company_name: str = Field(..., max_length=50, description="公司名字")
|
||||
salary: float = Field(..., ge=0.1, le=1000000.0, description="月薪")
|
||||
class StudentWorks(BaseModel):
|
||||
sid: int = Field(...,ge=0,le=10000,description="输入0-10000之间的你想修改的学生编号")
|
||||
# s_name:str =Field(...,max_length=50,description="学生姓名")
|
||||
# s_class : int = Field(...,ge = 1,le = 100,description="学生班级编号")
|
||||
open_time: date = Field(description="输入你修改后的时间,要写如下格式YYYY-MM-DD, ",default=date(1970,1,1))
|
||||
offer_time: date = Field( description="输入你修改后的时间,要写如下格式YYYY-MM-DD ",default=date(1970,1,1))
|
||||
company_name: str = Field( max_length=50, description="输入你修改后的公司名字",default="0")
|
||||
salary: float|int = Field( ge=0.1, le=100000.0, description="输入你修改后的月薪",default=0)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def time_available(self):
|
||||
if self.open_time > self.offer_time:
|
||||
raise HTTPException(status_code=422, detail="就业时间必须大于offer下发时间")
|
||||
return self
|
||||
# 允许 Pydantic 读取 SQLAlchemy ORM 对象
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user