This commit is contained in:
2023-11-13 22:04:27 +09:00
4 changed files with 12 additions and 5 deletions

View File

@@ -103,9 +103,11 @@ async def flow_details(
async def flow_list(
request: Request,
appid: str,
user=Depends(get_current_user),
db=Depends(get_db),
):
flows = get_flows_by_app(db, appid)
domain = get_activedomain(db, user.id)
flows = get_flows_by_app(db, domain.id, appid)
return flows
@@ -113,9 +115,11 @@ async def flow_list(
async def flow_create(
request: Request,
flow: FlowBase,
user=Depends(get_current_user),
db=Depends(get_db),
):
return create_flow(db, flow)
domain = get_activedomain(db, user.id)
return create_flow(db, domain.id, flow)
@r.put(

View File

@@ -125,11 +125,12 @@ def get_actions(db: Session):
return actions
def create_flow(db: Session, flow: schemas.FlowBase):
def create_flow(db: Session, domainid: int, flow: schemas.FlowBase):
db_flow = models.Flow(
flowid=flow.flowid,
appid=flow.appid,
eventid=flow.eventid,
domainid=domainid,
name=flow.name,
content=flow.content
)
@@ -176,8 +177,8 @@ def get_flow(db: Session, flowid: str):
raise HTTPException(status_code=404, detail="Data not found")
return flow
def get_flows_by_app(db: Session, appid: str):
flows = db.query(models.Flow).filter(models.Flow.appid == appid).all()
def get_flows_by_app(db: Session, domainid: int, appid: str):
flows = db.query(models.Flow).filter(and_(models.Flow.domainid == domainid,models.Flow.appid == appid)).all()
if not flows:
raise HTTPException(status_code=404, detail="Data not found")
return flows

View File

@@ -47,6 +47,7 @@ class Flow(Base):
flowid = Column(String(100), index=True, nullable=False)
appid = Column(String(100), index=True, nullable=False)
eventid = Column(String(100), index=True, nullable=False)
domainid = Column(Integer,ForeignKey("domain.id"))
name = Column(String(200))
content = Column(String)

View File

@@ -104,6 +104,7 @@ class Flow(Base):
flowid: str
appid: str
eventid: str
domainid: int
name: str = None
content: str = None