From 1b80ef0857f2ac9c0a2ec5538596795df4b821d5 Mon Sep 17 00:00:00 2001 From: wolin_chenyulin001 <123@163.com> Date: Mon, 21 Sep 2026 23:28:43 +0800 Subject: [PATCH] api,dao --- PythonProject/api/employment_api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index 2b827c3..6c022bf 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -1,5 +1,5 @@ from fastapi import APIRouter,Query,Depends,HTTPException -from starlette.middleware.sessions import Session +from util.database import get_db from dao import employment_dao from dao.employment_dao import get_emp_dao, add_emp_dao, check_stu_dao, update_emp_dao, delete_emp_dao @@ -12,19 +12,19 @@ def get_emp_info1(stu_id: Optional[int]=Query(None,description='学生编号') ,company_name: Optional[str]=Query(None,description='公司名称') ,min_salary: Optional[float]=Query(None,description='最低工资') ,max_salary: Optional[float]=Query(None,description='最高工资') - ,db:Session=Depends(get_db)): + ,db=Depends(get_db)): if stu_id or company_name or min_salary or max_salary: return [employment_dao.get_emp_dao(stu_id=stu_id,db=db)] raise HTTPException(status_code=404, detail='该学生就业信息不存在') @emp_api.get('/employment/class/{class_id}',response_model=EmploymentResponse,summary='获取班级学生就业信息') -def get_emp_info2(class_id: Optional[int],db:Session=Depends(get_db)): +def get_emp_info2(class_id: Optional[int],db=Depends(get_db)): if class_id: return employment_dao.get_emp_dao(class_id=class_id,db=db) raise HTTPException(status_code=404, detail='该班级就业信息不存在') @emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息') -def create_emp_info(stu_id:int,emp:EmploymentRequest,db:Session=Depends(get_db)): +def create_emp_info(stu_id:int,emp:EmploymentRequest,db=Depends(get_db)): if not check_stu_dao(stu_id,db): raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息') emp.stu_id = stu_id @@ -38,7 +38,7 @@ def create_emp_info(stu_id:int,emp:EmploymentRequest,db:Session=Depends(get_db)) return r @emp_api.put('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='更新学生就业信息') -def update_emp_info(stu_id:int,emp:EmploymentRequest,db:Session=Depends(get_db)): +def update_emp_info(stu_id:int,emp:EmploymentRequest,db=Depends(get_db)): d = emp.model_dump(exclude_unset=True) r = update_emp_dao(stu_id,d,db) if not r: @@ -46,7 +46,7 @@ def update_emp_info(stu_id:int,emp:EmploymentRequest,db:Session=Depends(get_db)) return {'code':200,'totals':r,'detail':'更新成功!'} @emp_api.delete('/employment/{stu_id}',summary='删除学生就业信息') -def delete_emp_info(stu_id:int,db:Session=Depends(get_db)): +def delete_emp_info(stu_id:int,db=Depends(get_db)): rows = delete_emp_dao(stu_id, db) if not rows: raise HTTPException(status_code=500, detail='没有删除!')