diff --git a/backend/app/api/api_v1/routers/platform.py b/backend/app/api/api_v1/routers/platform.py index b24f9fd..274c04e 100644 --- a/backend/app/api/api_v1/routers/platform.py +++ b/backend/app/api/api_v1/routers/platform.py @@ -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( diff --git a/backend/app/db/crud.py b/backend/app/db/crud.py index 9692e7c..d6a2860 100644 --- a/backend/app/db/crud.py +++ b/backend/app/db/crud.py @@ -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 diff --git a/backend/app/db/models.py b/backend/app/db/models.py index 7cb4e7d..e49ef53 100644 --- a/backend/app/db/models.py +++ b/backend/app/db/models.py @@ -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) diff --git a/backend/app/db/schemas.py b/backend/app/db/schemas.py index 5a8ee07..a85e5ed 100644 --- a/backend/app/db/schemas.py +++ b/backend/app/db/schemas.py @@ -104,6 +104,7 @@ class Flow(Base): flowid: str appid: str eventid: str + domainid: int name: str = None content: str = None