Skip to content

Commit

Permalink
add endpoint for get active sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshuamjv2 committed Oct 17, 2024
1 parent 6590833 commit 89fd6b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Binary file modified sessions/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified sessions/__pycache__/routes.cpython-39.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions sessions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from deps.auth.auth import get_current_user
from uuid import uuid4
from app.db import db
from datetime import datetime, timezone


# nest sessions in the database like:
Expand Down Expand Up @@ -36,6 +37,14 @@ async def get_sessions(user=Depends(get_current_user)):
return sessions


@router.get("/active_sessions", status_code=200)
async def get_active_sessions():
sessions = db["sessions"].find({"end_time": {"$gte": datetime.now(tz=timezone.utc)}})
if sessions:
return list(sessions)
return []


@router.get("/{id}", status_code=200)
async def get_single_session(id: str, user=Depends(get_current_user)):
session = db["sessions"].find_one({"_id": id})
Expand Down

0 comments on commit 89fd6b6

Please sign in to comment.