Skip to content

Commit

Permalink
steam list by query params
Browse files Browse the repository at this point in the history
  • Loading branch information
wkrzywiec committed Feb 14, 2025
1 parent 8f3cebd commit 7daba0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
11 changes: 6 additions & 5 deletions services/mankkoo/mankkoo/controller/stream_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ class StreamsQuery(Schema):
@stream_endpoints.doc(summary='List of streams', description='Get list of streams')
def streams(query_params):
log.info(f"Fetching all streams. Query: {str(query_params)}...")
log.info(type(query_params))

active: bool = None
type: str = None
if hasattr(query_params, "active"):
type_param: str = None
if "active" in query_params:
active = query_params["active"]

if hasattr(query_params, "type"):
type = query_params["type"]
if "type" in query_params:
type_param = query_params["type"]


streams = database.load_streams(active, type)
streams = database.load_streams(active, type=type_param)
return streams


Expand Down
21 changes: 12 additions & 9 deletions services/mankkoo/mankkoo/stream/stream_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ def load_streams(active: bool, type: str) -> list[Stream]:
log.info(f"Loading stream... Params: active={active}, type={type}")
conditions = []

# if active is not None:
# conditions.append(f"metadata->>'active' = '{active}'")
if active is not None:
conditions.append(f"CAST (metadata->>'active' AS boolean) = {active}")

# if type is not None:
# conditions.append(f"type = '{type}'")
if type is not None:
conditions.append(f"type = '{type}'")

# where_clause = ""
where_clause = ""

# if len(conditions) > 0:
# where_clause = f"WHERE {conditions[0]}"
if len(conditions) > 0:
where_clause = f"WHERE {conditions[0]}"

# if len(conditions) > 1:
# and_cond = " AND ".join()
if len(conditions) > 1:
conditions.pop(0)
and_cond = " AND ".join(conditions)
where_clause = where_clause + " AND " + and_cond

query = f"""
SELECT
Expand All @@ -39,6 +41,7 @@ def load_streams(active: bool, type: str) -> list[Stream]:
END AS name
FROM
streams
{where_clause}
;
"""

Expand Down

0 comments on commit 7daba0e

Please sign in to comment.