整体bug修改。
This commit is contained in:
+10
-4
@@ -9,14 +9,20 @@ from Teachers.schema.tea_response import TeaResponse
|
||||
|
||||
tea_api = APIRouter()
|
||||
|
||||
@tea_api.post('/tea',response_model=TeaResponse,summary='新增老师',description='输入新增的老师信息,除去姓名外可以为空')
|
||||
@tea_api.post('/tea'
|
||||
# ,response_model=TeaResponse
|
||||
,summary='新增老师'
|
||||
,description='输入新增的老师信息,除去姓名外可以为空')
|
||||
def add_tea(tea: NewTeaRequest=Depends(),db=Depends(get_db)):
|
||||
r = add_tea_dao(tea.model_dump(exclude_unset=True),db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=500,detail='添加失败!')
|
||||
return TeaResponse(totals=1,data=tea.model_dump())
|
||||
|
||||
@tea_api.get('/tea',response_model=TeaResponse,summary='查询老师',description='任意选择输入的信息数量,不输入则查询全部老师')
|
||||
return r #TeaResponse(totals=1,data=tea.model_dump())
|
||||
# r
|
||||
@tea_api.get('/tea'
|
||||
,response_model=TeaResponse
|
||||
,summary='查询老师'
|
||||
,description='任意选择输入的信息数量,不输入则查询全部老师')
|
||||
def get_tea(t:TeaRequest=Depends(),db=Depends(get_db)): #开启会话窗口
|
||||
r = get_tea_dao(t.model_dump(),db=db)
|
||||
if not r:
|
||||
|
||||
@@ -9,7 +9,7 @@ def add_tea_dao(t,db):
|
||||
not_delete = db.query(Tea).filter(Tea.phone ==t.get('phone'),Tea.is_delete == False).first()
|
||||
if not_delete:
|
||||
print('该老师已存在')
|
||||
raise Exception('老师已存在')
|
||||
raise Exception('该老师已存在,不可重复添加')
|
||||
existing = db.query(Tea).filter(Tea.phone == t.get('phone'),Tea.is_delete == True).first()
|
||||
if existing:
|
||||
for key,value in t.items():
|
||||
@@ -19,11 +19,11 @@ def add_tea_dao(t,db):
|
||||
#将value的值赋值到existing的key中,配合循环,让所有输入的信息都覆盖原信息
|
||||
existing.is_delete = False
|
||||
db.commit()
|
||||
return '恢复修改成功'
|
||||
return '新增成功-修订数据'
|
||||
t1 = Tea(**t)
|
||||
db.add(t1)
|
||||
db.commit()
|
||||
return True
|
||||
return '新增成功'
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print('新增失败原因',e)
|
||||
|
||||
@@ -17,16 +17,16 @@ def get_scores(score:ScoreQuery=Depends(),db=Depends(get_db)):
|
||||
@score_api.post('/Score'
|
||||
,summary='成绩添加')
|
||||
def add_scores(score:ScoreRequest=Depends(),db=Depends(get_db)):
|
||||
# try:
|
||||
try:
|
||||
a = score.model_dump()
|
||||
# print(a,type(a))
|
||||
aa = add_scores_dao(b=a,db=db)
|
||||
if aa:
|
||||
return aa
|
||||
# except ValueError as e:
|
||||
# raise HTTPException(status_code=400, detail="数据库已有该成绩")
|
||||
# except Exception as e:
|
||||
# raise HTTPException(status_code=500, detail="数据库错误")
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail="数据库已有该成绩")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail="数据库错误")
|
||||
|
||||
@score_api.put('/Score',summary='成绩更新',description=f'查询条件为学号,班级号,考试序次,考试科目,然后更改这位同学此次科目的成绩')
|
||||
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,t_subject:int,db=Depends(get_db)):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from zipfile import sizeCentralDir
|
||||
|
||||
|
||||
from scores.model.score_model import Score
|
||||
from datetime import datetime
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
from stu_jiuye.model import Employments,Address,Company
|
||||
from students.model.students_model import *
|
||||
from class_management.model.class_management_model import *
|
||||
|
||||
def add_employment_dao(o,db): #新增就业信息函数
|
||||
try:
|
||||
# r = db.query(Employments).filter(Employments.id == o['id'] ).all() #
|
||||
|
||||
@@ -26,7 +26,6 @@ select * from teachers limit 200;
|
||||
|
||||
select * from subject limit 200;
|
||||
|
||||
desc students;
|
||||
|
||||
|
||||
# select *
|
||||
|
||||
Reference in New Issue
Block a user