bugfix edit_flow

This commit is contained in:
2024-12-09 16:11:58 +09:00
parent 21e0b9d6df
commit b874d0c776
3 changed files with 68 additions and 8 deletions

View File

@@ -28,6 +28,9 @@ class dbflow(crudbase):
def get_domain_apps(self):
return None
def get_flow_by_flowid(self,db: Session,flowid:str):
return db.execute(super().get_by_conditions({"flowid":flowid})).scalars().first()
def get_flows_by_appid(self,db: Session,domainurl:str,appid:str):
return db.execute(select(models.Flow).filter(and_(models.Flow.domainurl == domainurl,models.Flow.appid == appid))).scalars().all()
@@ -58,7 +61,7 @@ class dbflow(crudbase):
db.commit()
db.refresh(db_flow)
return db_flow
dbflow = dbflow()
@@ -174,4 +177,25 @@ class dbapp(crudbase):
def create_flow(self,db: Session, domainurl: str, flow: schemas.FlowIn,userid:int):
return dbflow.create_flow(db,domainurl,flow,userid)
def edit_flow(self,db: Session, domainurl: str, flow: schemas.FlowIn,userid:int):
db_flow = dbflow.get_flow_by_flowid(db, flow.flowid)
if not db_flow:
return dbflow.create_flow(db,domainurl,flow,userid)
db_flow.appid =flow.appid
db_flow.eventid=flow.eventid
db_flow.domainurl=domainurl
db_flow.name=flow.name
db_flow.content=flow.content
db_flow.updateuserid = userid
db.add(db_flow)
db.commit()
db.refresh(db_flow)
return db_flow
def delete_flow(self,db: Session, flowid: str):
db_flow = dbflow.get_flow_by_flowid(db,flowid)
if db_flow:
return dbflow.delete(db,db_flow.id)
return None
appService = dbapp()