36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
from fastapi import APIRouter,Depends,HTTPException
|
|
from database import *
|
|
from schema.epy_schema import EmploymentRequest
|
|
from dao.epy_dao import get_employment_dao,wq_employment_dao,upd_employment_dao,del_employment_dao
|
|
epy_router = APIRouter()
|
|
|
|
|
|
@epy_router.get('',summary='查询就业信息')
|
|
def get_employment(stu_id:str,company:str,salary:int,db=Depends(get_db)): # get变动
|
|
try:
|
|
rows = get_employment_dao(db, stu_id, company, salary)
|
|
if not rows: # dao层返回的是q.() 是列表
|
|
return {'code':404,'detail':'数据不存在','total':[]} # 数据不存在返回报错信息
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f'查询失败:{str(e)}')
|
|
return {'code':200,'detail':'查询成功','date':[{'stu_id':i.stu_id,'company':i.company,'salary':i.salary} for i in rows]}
|
|
|
|
|
|
@epy_router.post('',summary='新增就业信息')
|
|
def add_employment(e:EmploymentRequest,db=Depends(get_db)):
|
|
d= e.model_dump()
|
|
r = wq_employment_dao(d,db)
|
|
return {'code':200,'detail':'添加成功!','total':r}
|
|
#
|
|
#
|
|
@epy_router.put('',summary='更新就业信息')
|
|
def update_employment(e:EmploymentRequest,db=Depends(get_db)):
|
|
e1 = e.model_dump()
|
|
r = upd_employment_dao(e1,db)
|
|
return {'code':200,'msg':'更新成功','total':r}
|
|
#
|
|
@epy_router.delete('',summary='删除就业信息')
|
|
def delete_employment(stu_id:str,db=Depends(get_db)):
|
|
r =del_employment_dao(stu_id,db)
|
|
return {'code':200,'totals':r,'detail':'删除成功!'}
|