Skip to content

Commit

Permalink
reports history
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha committed May 31, 2024
1 parent 34d777f commit 2746f38
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion routes/reports/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def get_report(report):
user = User.find(get_jwt_identity())

try:
report_data = general_report_service.get_report(user=user, report=report)
report_data = general_report_service.get_report(
user=user, report=report, filename=request.args.get("filename", "current")
)
except ValidationError as e:
return {"status": "error", "message": str(e), "code": e.code}, e.httpStatus

Expand Down
16 changes: 16 additions & 0 deletions services/reports/cache_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,19 @@ def get_cache_data(report, schema, filename="current"):
}
except ClientError:
return {"exists": False, "updatedAt": None}


def list_available_reports(schema: str, report: str):
client = _get_client()
files = client.list_objects_v2(
Bucket=Config.CACHE_BUCKET_NAME,
Prefix=f"reports/{schema}/{report}/",
)

file_list = []
for f in files["Contents"]:
filename = f["Key"].split("/")[-1].replace(".gz", "")
if filename != "current":
file_list.append(f["Key"].split("/")[-1].replace(".gz", ""))

return file_list
5 changes: 4 additions & 1 deletion services/reports/general_report_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ def get_report(user, report, filename="current"):

return {
"cached": True,
"url": cache_service.generate_link(report, user.schema),
"availableReports": cache_service.list_available_reports(
schema=user.schema, report=report
),
"url": cached_link,
}

0 comments on commit 2746f38

Please sign in to comment.