增删改查还在调试添加
This commit is contained in:
@@ -27,14 +27,18 @@ def add_scores(score:ScoreRequest=Depends(),db=Depends(get_db)):
|
||||
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,tsub:str,db=Depends(get_db)):
|
||||
a = score.model_dump(exclude_unset=True,exclude={'id','sid','cid','num','tsub'})
|
||||
aa = update_scores_dao(sid = sid,cid = cid,num = num,tsub = tsub,update_data = a,db=db)
|
||||
if not aa:
|
||||
raise HTTPException(status_code=404,detail='没有更新')
|
||||
if aa==-1:
|
||||
raise HTTPException(status_code=500,detail='没有更新')
|
||||
if aa==0:
|
||||
raise HTTPException(status_code=404,detail='不存在')
|
||||
return {'message':'更新成功','data':a}
|
||||
|
||||
@score_api.delete('/Score')
|
||||
def delete_scores(sid:int,cid:int,tsub:str,db=Depends(get_db)):
|
||||
aaa = delete_scores_dao(sid,cid,tsub,db)
|
||||
if not aaa:
|
||||
if aaa==1:
|
||||
raise HTTPException(status_code=500,detail='删除失败')
|
||||
if aaa==0:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
return {'message':'更新成功','detail':aaa}
|
||||
|
||||
|
||||
+18
-12
@@ -1,4 +1,5 @@
|
||||
from scores.model.score_model import Score
|
||||
from datetime import datetime
|
||||
|
||||
def get_scores_dao(s,db):
|
||||
ab = db.query(Score).filter(Score.is_deleted ==0)
|
||||
@@ -42,31 +43,36 @@ def add_scores_dao(b,db):
|
||||
db.commit()
|
||||
return True
|
||||
|
||||
def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
|
||||
def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_date:dict,db):
|
||||
if not update_date:
|
||||
return 0
|
||||
update_date['update_date']=datetime.now
|
||||
try:
|
||||
aa = db.query(Score).filter(Score.sid == sid
|
||||
,Score.cid == cid
|
||||
,Score.num == num
|
||||
,Score.tsub == tsub ).update(update_data)
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
,Score.tsub == tsub ).update(update_date)
|
||||
db.commit()
|
||||
return aa
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(e)
|
||||
return -1
|
||||
|
||||
|
||||
def delete_scores_dao(sid:int,cid:int,tsub:str,db):
|
||||
try:
|
||||
aaa = db.query(Score).filter(Score.sid ==sid
|
||||
,Score.cid == cid
|
||||
,Score.tsub == tsub
|
||||
,Score.is_deleted==0).delete()
|
||||
except:
|
||||
db.rollback()
|
||||
aaa = 0
|
||||
else:
|
||||
,Score.is_deleted==0
|
||||
).update({'is_deleted':1
|
||||
,'deleted_date':datetime.now})
|
||||
db.commit()
|
||||
finally:
|
||||
return aaa
|
||||
except Exception :
|
||||
db.rollback()
|
||||
return -1
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class Score(Base):
|
||||
)
|
||||
update_date = Column(DateTime
|
||||
,default = datetime.now
|
||||
)
|
||||
)
|
||||
is_deleted = Column(Integer
|
||||
,default = 0
|
||||
,comment='是否删除: 0-正常,1-已删除'
|
||||
|
||||
Reference in New Issue
Block a user