diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index e69de29..68cc125 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -0,0 +1,30 @@ +from fastapi import FastAPI,APIRouter,Depends,HTTPException + +from dao import employment_dao +from dao.employment_dao import get_employment_dao +from schema.employment_schema import EmlpoymentRequest,EmploymentResponse +from model.all_model import ClassManagement,Employment_info +from util.database import get_db + +app = FastAPI() +@app.get('employment/students/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息') +def get_emp_info1(stu_id: int,db=Depends(get_db)): + try: + if stu_id: + return employment_dao.get_employment_info() + except: + raise HTTPException(status_code=404, detail='就业信息不存在') + +@app.get('employment/class/{class_id}',summary='获取班级学生就业信息') +def get_emp_info2(class_id: int,db=Depends(get_db)): + try: + if class_id: + return employment_dao.get_employment_info() + except: + raise HTTPException(status_code=404, detail='就业信息不存在') + + + +@app.post('employment/students/{stu_id}') +def create_emp_info(stu_id: int,db=Depends(get_db)): + diff --git a/PythonProject/dao/employment_dao.py b/PythonProject/dao/employment_dao.py index e69de29..47275fb 100644 --- a/PythonProject/dao/employment_dao.py +++ b/PythonProject/dao/employment_dao.py @@ -0,0 +1,40 @@ + +from model.all_model import Employment_info, ClassManagement, Student_Model +from util.database import get_db +from schema.employment_schema import EmlpoymentRequest + +def get_employment_dao(stu_id,class_id,db): + q = db.query(Employment_info).\ + join(ClassManagement,ClassManagement.stu_id == Employment_info.stu_id).\ + filter(Employment_info.delete_status == 0).\ + filter(Student_Model.delete_status == 0).\ + filter(ClassManagement.delete_status == 0) + if stu_id is not None: + q = q.filter(Employment_info.stu_id == stu_id) + if class_id is not None: + q = q.filter(ClassManagement.class_id == class_id) + r = q.all() + if r: + return [{'emp_id':i.emp_id + ,'stu_id': i.stu_id + ,'stu_name':i.stu_name + ,'class_id':i.class_id + ,'email':i.email + ,'employment_opening_date':i.employment_opening_date + ,'offer_issuance_date':i.offer_issuance_date + ,'company_name':i.company_name + ,'company_address':i.company_address + ,'salary':i.salary + }for i in r + ] + +def add_employment_dao(e:EmlpoymentRequest,db,stu_id): + try: + e1 = Employment_info(**e) + db.add(e1) + except: + db.rollback() + return False + else: + db.commit() + return True diff --git a/PythonProject/schema/employment_schema.py b/PythonProject/schema/employment_schema.py index 47a153f..d353b40 100644 --- a/PythonProject/schema/employment_schema.py +++ b/PythonProject/schema/employment_schema.py @@ -1,12 +1,13 @@ from fastapi import Query,HTTPException from pydantic import BaseModel, field_validator -from datetime import datetime +from datetime import date +from typing import Optional class EmlpoymentRequest(BaseModel): stu_id: int=Query(ge=1) email: str|None - employment_opening_date:datetime - offer_issuance_date:datetime + employment_opening_date:date + offer_issuance_date:date company_name:str company_address:str|None salary:float @@ -21,10 +22,13 @@ class EmlpoymentRequest(BaseModel): 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: datetime - offer_issuance_date: datetime + employment_opening_date: date + offer_issuance_date: date company_name: str company_address: str | None salary: float \ No newline at end of file