-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
06be1fa
commit 347f2ad
Showing
6 changed files
with
107 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from models.databases.supabase.api_key_handler import ApiKeyHandler | ||
from models.databases.supabase.brains import Brain | ||
from models.databases.supabase.brains_subscription_invitations import \ | ||
BrainSubscription | ||
from models.databases.supabase.brains_subscription_invitations import BrainSubscription | ||
from models.databases.supabase.chats import Chats | ||
from models.databases.supabase.files import File | ||
from models.databases.supabase.knowledge import Knowledges | ||
from models.databases.supabase.notifications import Notifications | ||
from models.databases.supabase.onboarding import Onboarding | ||
from models.databases.supabase.prompts import Prompts | ||
from models.databases.supabase.user_usage import UserUsage | ||
from models.databases.supabase.vectors import Vector |
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,62 @@ | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from fastapi import HTTPException | ||
from models.databases.repository import ( | ||
Repository, # Assuming you have a repository class | ||
) | ||
from models.onboarding import Onboardings | ||
from pydantic import BaseModel | ||
|
||
|
||
class OnboardingUpdatableProperties(BaseModel): | ||
"""Properties that can be received on onboarding update""" | ||
|
||
onboarding_b1: Optional[bool] | ||
onboarding_b2: Optional[bool] | ||
onboarding_b3: Optional[bool] | ||
|
||
|
||
class Onboarding(Repository): | ||
def __init__(self, supabase_client): | ||
self.db = supabase_client | ||
|
||
def get_user_onboarding(self, user_id: UUID) -> Onboardings: | ||
""" | ||
Get user onboarding information by user_id | ||
""" | ||
onboarding_data = ( | ||
self.db.from_("onboarding") | ||
.select("user_id", "onboarding_b1", "onboarding_b2", "onboarding_b3") | ||
.filter("user_id", "eq", user_id) | ||
.limit(1) | ||
.execute() | ||
).data | ||
|
||
if not onboarding_data: | ||
raise HTTPException(404, "User onboarding not found") | ||
|
||
return Onboardings(**onboarding_data[0]) | ||
|
||
def update_user_onboarding( | ||
self, user_id: UUID, onboarding: OnboardingUpdatableProperties | ||
) -> Onboardings: | ||
"""Update user onboarding information by user_id""" | ||
response = ( | ||
self.db.from_("onboarding") | ||
.upsert( | ||
{ | ||
"user_id": user_id, | ||
"onboarding_b1": onboarding.onboarding_b1, | ||
"onboarding_b2": onboarding.onboarding_b2, | ||
"onboarding_b3": onboarding.onboarding_b3, | ||
}, | ||
unique_keys=["user_id"], | ||
) | ||
.execute() | ||
.data | ||
) | ||
|
||
if not response: | ||
raise HTTPException(404, "User onboarding not updated") | ||
return Onboardings(**response[0]) |
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,18 @@ | ||
from uuid import UUID | ||
|
||
from models.onboarding import Onboardings | ||
from models.settings import get_supabase_db | ||
|
||
|
||
def get_user_onboarding(user_id: UUID) -> Onboardings: | ||
""" | ||
Get a user's onboarding status | ||
Args: | ||
user_id (UUID): The id of the user | ||
Returns: | ||
Onboardings: The user's onboarding status | ||
""" | ||
supabase_db = get_supabase_db() | ||
return supabase_db.get_user_onboarding(user_id) |
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,14 @@ | ||
from uuid import UUID | ||
|
||
from models.databases.supabase.onboarding import OnboardingUpdatableProperties | ||
from models.onboarding import Onboardings | ||
from models.settings import get_supabase_db | ||
|
||
|
||
def update_user_onboarding( | ||
user_id: UUID, onboarding: OnboardingUpdatableProperties | ||
) -> Onboardings: | ||
"""Update user onboarding information by user_id""" | ||
|
||
supabase_db = get_supabase_db() | ||
return supabase_db.update_user_onboarding(user_id, onboarding) |