Files
SST/PythonProject/schema/employment_schema.py
T

40 lines
1.1 KiB
Python

from fastapi import HTTPException
from pydantic import BaseModel, Field,field_validator, model_validator
from datetime import date
from typing import Optional
class EmploymentRequest(BaseModel):
stu_id: int=Field(ge=1)
email: str|None
employment_opening_date:date
offer_issuance_date:date
company_name:str
company_address:str|None
salary:float
@field_validator('stu_id')
@classmethod
def check_stu_id(cls,v):
if v <= 0:
raise ValueError('输入有误,学生ID必须大于0')
return v
@model_validator(mode='after')
def check_date(self):
if self.employment_opening_date > self.offer_issuance_date:
raise ValueError('offer下发日期不能早于就业开放日期')
return self
class EmploymentResponse(BaseModel):
code:int = 200
detail:str = 'OK'
emp_id:int
stu_id: int
stu_name:Optional[str] = None
class_id:int
email: str | None
employment_opening_date: date
offer_issuance_date: date
company_name: str
company_address: str | None
salary: float