-
Notifications
You must be signed in to change notification settings - Fork 0
Cookie ids #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookie ids #146
Changes from all commits
e69bae5
1c6f355
a3bd736
380d2de
b04928e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| from welearn_database.data.models import Bookmark, InferredUser, Session | ||
|
|
||
| from src.app.services.sql_db.sql_service import session_maker | ||
| from src.app.shared.domain.exceptions import SessionNotFoundError, UserNotFoundError | ||
| from src.app.utils.logger import logger as logger_utils | ||
|
|
||
| logger = logger_utils(__name__) | ||
|
|
@@ -27,6 +28,8 @@ def get_or_create_user_sync( | |
| ).first() | ||
| if user: | ||
| return user.id | ||
|
|
||
| logger.info("Creating new user with referer: %s", referer) | ||
| user = InferredUser(origin_referrer=referer) | ||
| s.add(user) | ||
| s.commit() | ||
|
|
@@ -45,7 +48,7 @@ def get_or_create_session_sync( | |
| select(InferredUser.id).where(InferredUser.id == user_id) | ||
| ).first() | ||
| if not user: | ||
| raise ValueError(f"User {user_id} does not exist") | ||
| raise UserNotFoundError(f"User {user_id} does not exist") | ||
|
|
||
| if session_id: | ||
| session = s.execute( | ||
|
|
@@ -58,6 +61,9 @@ def get_or_create_session_sync( | |
| if session: | ||
| return session.id | ||
|
|
||
| logger.info( | ||
| "Creating new session for user_id=%s with referer: %s", user_id, referer | ||
| ) | ||
| new_session = Session( | ||
| inferred_user_id=user_id, | ||
| origin_referrer=referer, | ||
|
|
@@ -70,11 +76,21 @@ def get_or_create_session_sync( | |
| return new_session.id | ||
|
|
||
|
|
||
| def get_user_from_session_id(session_id: uuid.UUID) -> uuid.UUID | None: | ||
| def get_user_from_session_id(session_id: uuid.UUID | None) -> uuid.UUID | None: | ||
| if not session_id: | ||
| return None | ||
|
|
||
| with session_maker() as s: | ||
| session = s.execute(select(Session).where(Session.id == session_id)).first() | ||
| if session: | ||
| logger.info( | ||
| "Valid session. user_id=%s session_id=%s", | ||
| session[0].inferred_user_id, | ||
| session_id, | ||
| ) | ||
| return session[0].inferred_user_id | ||
|
Comment on lines
83
to
91
|
||
| else: | ||
| raise SessionNotFoundError(f"Session with id {session_id} not found") | ||
| return None | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.