Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Krrupa committed May 28, 2024
2 parents d6e0924 + ac02ebb commit f69b5d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ class SessionResponse(BaseModel):
popup_form: Optional[str] = None
signup_form_id: Optional[str] = None
popup_form_id: Optional[str] = None
session_occurrence_id: Optional[str] = None


class UserSession(BaseModel):
user_id: str
session_id: str
session_occurrence_id: int
is_user_valid: bool
user_activity_type: str
user_type: str
data: Optional[Dict] = {}
5 changes: 4 additions & 1 deletion app/router/session_occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ async def get_session_occurrence_data(request: Request):
response = requests.get(
session_occurrence_db_url, params=query_params, headers=db_request_token()
)

if response.status_code == 200:
if len(response.json()) != 0:
session_occurrence_data = response.json()
Expand All @@ -112,7 +113,9 @@ async def get_session_occurrence_data(request: Request):
session_data = response.json()[0]
if session_data["is_active"]:
session_data["is_session_open"] = True

session_data[
"session_occurrence_id"
] = matched_session_occurrences[0]["id"]
return session_data
return {"is_session_open": False}
raise HTTPException(
Expand Down
17 changes: 16 additions & 1 deletion app/router/user_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@
from datetime import datetime
from routes import user_session_db_url
from helpers import db_request_token, is_response_valid, is_response_empty
from router import student, session, user
from request import build_request

router = APIRouter(prefix="/user-session", tags=["User-Session"])


@router.post("/")
def user_session(user_session: UserSession):
async def user_session(user_session: UserSession):
query_params = user_session.dict()
query_params["timestamp"] = datetime.now().isoformat()

if query_params["user_type"] == "student":
user_id_response = student.get_students(
build_request(query_params={"student_id": query_params["user_id"]})
)

query_params["user_id"] = user_id_response[0]["user"]["id"]

session_pk_id_response = await session.get_session(
build_request(query_params={"session_id": query_params["session_id"]})
)
query_params["session_id"] = session_pk_id_response[0]["id"]

response = requests.post(
user_session_db_url, json=query_params, headers=db_request_token()
)
Expand Down

0 comments on commit f69b5d8

Please sign in to comment.