Skip to content
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

feat: update onboarding controller and fix typo #1333

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from routes.knowledge_routes import knowledge_router
from routes.misc_routes import misc_router
from routes.notification_routes import notification_router
from routes.onboarding_routes import onboarding_router
from routes.prompt_routes import prompt_router
from routes.subscription_routes import subscription_router
from routes.upload_routes import upload_router
Expand Down Expand Up @@ -49,8 +50,10 @@ async def startup_event():
app.include_router(brain_router)
app.include_router(chat_router)
app.include_router(crawl_router)
app.include_router(onboarding_router)
app.include_router(explore_router)
app.include_router(misc_router)

app.include_router(upload_router)
app.include_router(user_router)
app.include_router(api_key_router)
Expand Down
34 changes: 18 additions & 16 deletions backend/models/databases/supabase/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@
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 GetOnboardingResponse(BaseModel):
"""Response when getting onboarding"""

onboarding_b1: bool
onboarding_b2: bool
onboarding_b3: bool


class Onboarding(Repository):
def __init__(self, supabase_client):
self.db = supabase_client

def get_user_onboarding(self, user_id: UUID) -> Onboardings:
def get_user_onboarding(self, user_id: UUID) -> GetOnboardingResponse | None:
"""
Get user onboarding information by user_id
"""
Expand All @@ -33,30 +41,24 @@ def get_user_onboarding(self, user_id: UUID) -> Onboardings:
.execute()
).data

if not onboarding_data:
raise HTTPException(404, "User onboarding not found")
if onboarding_data == []:
return None

return Onboardings(**onboarding_data[0])
return GetOnboardingResponse(**onboarding_data[0])

def update_user_onboarding(
self, user_id: UUID, onboarding: OnboardingUpdatableProperties
) -> Onboardings:
) -> GetOnboardingResponse:
"""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"],
)
.update(onboarding.dict())
.match({"user_id": user_id})
.execute()
.data
)

if not response:
raise HTTPException(404, "User onboarding not updated")
return Onboardings(**response[0])

return GetOnboardingResponse(**response[0])
2 changes: 0 additions & 2 deletions backend/models/onboarding.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from dataclasses import dataclass
from uuid import UUID

from pydantic import BaseModel


@dataclass
class Onboardings(BaseModel):
user_id: UUID
onboarding_b1: bool
Expand Down
4 changes: 2 additions & 2 deletions backend/repository/onboarding/get_user_onboarding.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from uuid import UUID

from models.onboarding import Onboardings
from models.databases.supabase.onboarding import GetOnboardingResponse
from models.settings import get_supabase_db


def get_user_onboarding(user_id: UUID) -> Onboardings:
def get_user_onboarding(user_id: UUID) -> GetOnboardingResponse | None:
"""
Get a user's onboarding status
Expand Down
8 changes: 5 additions & 3 deletions backend/repository/onboarding/udpate_user_onboarding.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from uuid import UUID

from models.databases.supabase.onboarding import OnboardingUpdatableProperties
from models.onboarding import Onboardings
from models.databases.supabase.onboarding import (
GetOnboardingResponse,
OnboardingUpdatableProperties,
)
from models.settings import get_supabase_db


def update_user_onboarding(
user_id: UUID, onboarding: OnboardingUpdatableProperties
) -> Onboardings:
) -> GetOnboardingResponse:
"""Update user onboarding information by user_id"""

supabase_db = get_supabase_db()
Expand Down
9 changes: 6 additions & 3 deletions backend/routes/onboarding_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
get_current_user, # Assuming you have a get_current_user function
)
from fastapi import APIRouter, Depends
from models.databases.supabase.onboarding import OnboardingUpdatableProperties
from models.databases.supabase.onboarding import (
GetOnboardingResponse,
OnboardingUpdatableProperties,
)
from models.user_identity import UserIdentity
from repository.onboarding.get_user_onboarding import get_user_onboarding
from repository.onboarding.udpate_user_onboarding import update_user_onboarding
Expand All @@ -18,7 +21,7 @@
)
async def get_user_onboarding_handler(
current_user: UserIdentity = Depends(get_current_user),
):
) -> GetOnboardingResponse | None:
"""
Get user onboarding information for the current user
"""
Expand All @@ -34,7 +37,7 @@ async def get_user_onboarding_handler(
async def update_user_onboarding_handler(
onboarding: OnboardingUpdatableProperties,
current_user: UserIdentity = Depends(get_current_user),
):
) -> GetOnboardingResponse:
"""
Update user onboarding information for the current user
"""
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/en/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"download_message_2": "Step 1: Download “Quivr documentation”",
"upload_message_1": "Congratulations on your first step 🥳",
"upload_message_2": "Step 2: Now Drag and drop it on the chat or in the 📎",
"how_to_use_quivr": "How to user Quivr",
"how_to_use_quivr": "How to use Quivr ?",
"what_is_quivr": "What is Quivr ?",
"what_is_brain": "What is a brain ?",
"last_step": "Last step 🥳",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/es/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"download_message_2": "Paso 1: Descargar la documentación de “Quivr”",
"upload_message_1": "¡Felicidades por tu primer paso 🥳!",
"upload_message_2": "Paso 2: Ahora, arrástralo y suéltalo en el chat o en el 📎",
"how_to_use_quivr": "Cómo usar Quivr",
"how_to_use_quivr": "¿Cómo usar Quivr?",
"what_is_quivr": "¿Qué es Quivr?",
"what_is_brain": "¿Qué es un cerebro?",
"last_step":"Último paso 🥳",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/fr/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"download_message_2": "Étape 1 : Téléchargez la documentation de “Quivr”",
"upload_message_1": "Félicitations pour votre première étape 🥳!",
"upload_message_2": "Étape 2 : Maintenant, faites glisser et déposez-le dans le chat ou dans 📎",
"how_to_use_quivr": "Comment utiliser Quivr",
"how_to_use_quivr": "Comment utiliser Quivr ?",
"what_is_quivr": "Qu'est-ce que Quivr ?",
"what_is_brain": "Qu'est-ce qu'un cerveau ?",
"last_step":"Dernière étape 🥳",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/pt-br/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"download_message_2": "Passo 1: Baixe a documentação do 'Quivr'",
"upload_message_1": "Parabéns pelo seu primeiro passo 🥳!",
"upload_message_2": "Passo 2: Agora, arraste e solte no chat ou na 📎",
"how_to_use_quivr": "Como usar o Quivr",
"how_to_use_quivr": "Como usar o Quivr?",
"what_is_quivr": "O que é o Quivr?",
"what_is_brain": "O que é um cérebro?",
"last_step":"Dernière étape 🥳",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/ru/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"download_message_2": "Шаг 1: Скачайте документацию Quivr",
"upload_message_1": "Поздравляем с первым шагом 🥳!",
"upload_message_2": "Шаг 2: Теперь перетащите его в чат или в 📎",
"how_to_use_quivr": "Как использовать Quivr",
"how_to_use_quivr": "Как использовать Quivr?",
"what_is_quivr": "Что такое Quivr?",
"what_is_brain": "Что такое мозг?",
"last_step":"Последний шаг 🥳",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/zh-cn/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"download_message_2": "步骤 1:下载“Quivr 文档”",
"upload_message_1": "恭喜您迈出第一步 🥳!",
"upload_message_2": "第2步:现在,将其拖放到聊天框或 📎 中",
"how_to_use_quivr": "如何使用Quivr",
"how_to_use_quivr": "如何使用Quivr",
"what_is_quivr": "什么是Quivr?",
"what_is_brain": "什么是大脑?",
"last_step":"最后一步 🥳",
Expand Down
Loading