-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
500567b
commit 69d31b5
Showing
6 changed files
with
99 additions
and
14 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,41 @@ | ||
from fastapi import APIRouter, Depends, Response, HTTPException | ||
from api.dependencies.authenticated import get_user_dep | ||
from tools import bson_to_json | ||
from crud.sessions import get_user_sessions, delete_session, get_session_by_id | ||
from api.model import SessionListResponseModel | ||
|
||
router = APIRouter( | ||
prefix="/sessions", | ||
tags=["Sessions"], | ||
dependencies=[Depends(get_user_dep)], | ||
) | ||
|
||
|
||
@router.get("", response_model=SessionListResponseModel) | ||
async def sessions_list(user: dict = Depends(get_user_dep)): | ||
""" | ||
# Get Sessions | ||
## Description | ||
This endpoint is used to get the sessions of the user. | ||
""" | ||
sesss = get_user_sessions(user["_id"]) | ||
sesss = [bson_to_json(sess) for sess in sesss] | ||
return {"sessions": sesss} | ||
|
||
|
||
@router.delete("/{session_id}") | ||
async def delete_other_session(session_id: str, user: dict = Depends(get_user_dep)): | ||
""" | ||
# Delete Session | ||
## Description | ||
This endpoint is used to delete a session. | ||
""" | ||
sess_to_delete = get_session_by_id(session_id) | ||
if not sess_to_delete: | ||
raise HTTPException(status_code=404, detail="Session not found.") | ||
if sess_to_delete["user_id"] != user["_id"]: | ||
raise HTTPException(status_code=404, detail="Session not found.") | ||
delete_session(sess_to_delete["session_token"]) | ||
return Response(status_code=204) |
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