修改put和delete的路径参数为stu_id
This commit is contained in:
@@ -39,16 +39,16 @@ def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
|
|||||||
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
|
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@emp_api.put('/employment/students/{emp_id}',summary='更新学生就业信息')
|
@emp_api.put('/employment/students/{stu_id}',summary='更新学生就业信息')
|
||||||
def update_emp_info(emp_id:int,emp:UpdateEmpRequest,db=Depends(get_db)):
|
def update_emp_info(stu_id:int,emp:UpdateEmpRequest,db=Depends(get_db)):
|
||||||
r = update_emp_dao(emp_id,emp.model_dump(exclude_unset=True),db)
|
r = update_emp_dao(stu_id,emp.model_dump(exclude_unset=True),db)
|
||||||
if not r:
|
if not r:
|
||||||
raise HTTPException(status_code=500,detail='没有更新!')
|
raise HTTPException(status_code=500,detail='没有更新!')
|
||||||
return {'code':200,'totals':r,'detail':'更新成功!'}
|
return {'code':200,'totals':r,'detail':'更新成功!'}
|
||||||
|
|
||||||
@emp_api.delete('/employment/{emp_id}',summary='删除学生就业信息')
|
@emp_api.delete('/employment/{stu_id}',summary='删除学生就业信息')
|
||||||
def delete_emp_info(emp_id:int=Path(description='序号'),db=Depends(get_db)):
|
def delete_emp_info(stu_id:int=Path(description='序号'),db=Depends(get_db)):
|
||||||
rows = delete_emp_dao(emp_id, db)
|
rows = delete_emp_dao(stu_id, db)
|
||||||
if not rows:
|
if not rows:
|
||||||
raise HTTPException(status_code=500, detail='没有删除!')
|
raise HTTPException(status_code=500, detail='没有删除!')
|
||||||
return {'code':200,'detail':'删除成功!'}
|
return {'code':200,'detail':'删除成功!'}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ def add_emp_dao(o,db):
|
|||||||
if not stu:
|
if not stu:
|
||||||
raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息')
|
raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息')
|
||||||
|
|
||||||
exist = (db.query(Employment_info).filter(Employment_info.stu_id == o['stu_id']
|
exist = db.query(Employment_info).filter(Employment_info.stu_id == o['stu_id']
|
||||||
,Employment_info.delete_status == 0).first())
|
,Employment_info.delete_status == 0).first()
|
||||||
if exist:
|
if exist:
|
||||||
raise HTTPException(status_code=409, detail='该学生已有就业信息,请勿重复增加!')
|
raise HTTPException(status_code=409, detail='该学生已有就业信息,请勿重复增加!')
|
||||||
|
|
||||||
@@ -54,22 +54,22 @@ def add_emp_dao(o,db):
|
|||||||
db.rollback()
|
db.rollback()
|
||||||
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
||||||
|
|
||||||
def update_emp_dao(emp_id,emp,db):
|
def update_emp_dao(stu_id,emp,db):
|
||||||
try:
|
try:
|
||||||
rows = db.query(Employment_info)\
|
rows = db.query(Employment_info)\
|
||||||
.filter(Employment_info.emp_id == emp_id,Employment_info.delete_status == 0)\
|
.filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0)\
|
||||||
.update(emp)
|
.update(emp)
|
||||||
db.commit()
|
db.commit()
|
||||||
return rows
|
return rows
|
||||||
except:
|
except:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
raise HTTPException(status_code=404,detail='该就业记录已存在')
|
raise HTTPException(status_code=404,detail='该就业记录不存在')
|
||||||
|
|
||||||
|
|
||||||
def delete_emp_dao(emp_id:int,db):
|
def delete_emp_dao(stu_id:int,db):
|
||||||
try:
|
try:
|
||||||
rows = db.query(Employment_info)\
|
rows = db.query(Employment_info)\
|
||||||
.filter(Employment_info.emp_id == emp_id
|
.filter(Employment_info.stu_id == stu_id
|
||||||
,Employment_info.delete_status == 0)\
|
,Employment_info.delete_status == 0)\
|
||||||
.update({'delete_status':1,'delete_time': datetime.now()})
|
.update({'delete_status':1,'delete_time': datetime.now()})
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user