Skip to content

Commit

Permalink
✨ add endpoint for getting the numbers of visits for a page
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikMorstad committed Nov 26, 2023
1 parent 1e8d70a commit e03f439
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/api/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ def get_page_visits(request: Request, page: str, start: Optional[str] = None, en

return add_continous_datapoints_to_log(visits, start_date, end_date, Interval.day)

@router.get('/get-all-page-visits')
def get_all_page_visits(request: Request, page: str, token: AccessTokenPayload = Depends(authorize_admin)):
db = get_database(request)
pipeline = [
{"$match": {"metaData": page}},
{"$group": {
"_id": "$metaData",
"count": {"$sum": 1}
}}
]
res = db.pageVisitLog.aggregate(pipeline)

db.pageVisitLog.find({"metaData": page})
if res == None:
raise HTTPException(500, "Problems retrieving page from database")
page_visits_list = list(res)
if len(page_visits_list) == 0:
raise HTTPException(404, "Could not find page")
visits = page_visits_list[0]
return {"visits": visits["count"]}

@router.get('/most_visited_pages_last_month')
def get_most_visited_page(request: Request, token: AccessTokenPayload = Depends(authorize_admin)):
db = get_database(request)
Expand Down

0 comments on commit e03f439

Please sign in to comment.