-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from apiflask import APIBlueprint, Schema | ||
from apiflask.fields import String, Boolean, Integer | ||
|
||
from mankkoo.stream import stream_db as database | ||
from mankkoo.stream.stream_db import Stream, StreamDetails | ||
from mankkoo.base_logger import log | ||
|
||
stream_endpoints = APIBlueprint('stream_endpoints', __name__, tag='Stream') | ||
|
||
|
||
class StreamsQuery(Schema): | ||
active = Boolean() | ||
type = String() | ||
|
||
@stream_endpoints.route("", methods=['GET']) | ||
@stream_endpoints.input(StreamsQuery, location='query') | ||
@stream_endpoints.output(Stream(many=True), status_code=200) | ||
@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)}...") | ||
|
||
active: bool = None | ||
type: str = None | ||
if hasattr(query_params, "active"): | ||
active = query_params["active"] | ||
|
||
if hasattr(query_params, "type"): | ||
type = query_params["type"] | ||
|
||
|
||
streams = database.load_streams(active, type) | ||
return streams | ||
|
||
|
||
|
||
@stream_endpoints.route("/<stream_id>") | ||
@stream_endpoints.output(StreamDetails, status_code=200) | ||
@stream_endpoints.doc( | ||
summary='Stream by id', | ||
description='Get detailed information about the Stream' | ||
) | ||
def stream_by_id(stream_id): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from apiflask import Schema | ||
from apiflask.fields import String, Integer | ||
|
||
import mankkoo.database as db | ||
from mankkoo.base_logger import log | ||
|
||
class Stream(Schema): | ||
id = String() | ||
type = String() | ||
name = String() | ||
|
||
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 type is not None: | ||
# conditions.append(f"type = '{type}'") | ||
|
||
# where_clause = "" | ||
|
||
# if len(conditions) > 0: | ||
# where_clause = f"WHERE {conditions[0]}" | ||
|
||
# if len(conditions) > 1: | ||
# and_cond = " AND ".join() | ||
|
||
query = f""" | ||
SELECT | ||
id, type, | ||
CASE | ||
WHEN type = 'account' THEN CONCAT(metadata->>'bankName', ' - ', metadata->>'alias') | ||
WHEN type = 'investment' THEN metadata->>'investmentName' | ||
WHEN type = 'retirement' THEN metadata->>'alias' | ||
WHEN type = 'stocks' AND metadata->>'type' = 'ETF' THEN metadata->>'etfName' | ||
ELSE 'Unknown' | ||
END AS name | ||
FROM | ||
streams | ||
; | ||
""" | ||
|
||
result = [] | ||
with db.get_connection() as conn: | ||
with conn.cursor() as cur: | ||
cur.execute(query) | ||
rows = cur.fetchall() | ||
|
||
for row in rows: | ||
stream = Stream() | ||
stream.id = row[0] | ||
stream.type = row[1] | ||
stream.name = row[2] | ||
|
||
result.append(stream) | ||
return result | ||
|
||
|
||
class StreamDetails(Schema): | ||
id = String() | ||
type = String() | ||
version = Integer() | ||
|