From 28ef5154583766c204d5926b6adafa669dc683b9 Mon Sep 17 00:00:00 2001 From: Mamadou DICKO <63923024+mamadoudicko@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:31:26 +0200 Subject: [PATCH] feat: update onboarding controller and fix typo (#1333) Screenshot 2023-10-05 at 10 55 29 Screenshot 2023-10-05 at 10 49 45 https://github.com/StanGirard/quivr/issues/1328 --- backend/main.py | 3 ++ .../models/databases/supabase/onboarding.py | 34 ++++++++++--------- backend/models/onboarding.py | 2 -- .../onboarding/get_user_onboarding.py | 4 +-- .../onboarding/udpate_user_onboarding.py | 8 +++-- backend/routes/onboarding_routes.py | 9 +++-- frontend/public/locales/en/chat.json | 2 +- frontend/public/locales/es/chat.json | 2 +- frontend/public/locales/fr/chat.json | 2 +- frontend/public/locales/pt-br/chat.json | 2 +- frontend/public/locales/ru/chat.json | 2 +- frontend/public/locales/zh-cn/chat.json | 2 +- 12 files changed, 40 insertions(+), 32 deletions(-) diff --git a/backend/main.py b/backend/main.py index 588627ae1..410a0f55b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -21,6 +21,7 @@ from routes.explore_routes import explore_router 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 @@ -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) diff --git a/backend/models/databases/supabase/onboarding.py b/backend/models/databases/supabase/onboarding.py index c9158c749..7a49149d3 100644 --- a/backend/models/databases/supabase/onboarding.py +++ b/backend/models/databases/supabase/onboarding.py @@ -5,11 +5,11 @@ 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] @@ -17,11 +17,19 @@ class OnboardingUpdatableProperties(BaseModel): 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 """ @@ -33,30 +41,24 @@ class Onboarding(Repository): .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]) diff --git a/backend/models/onboarding.py b/backend/models/onboarding.py index 55bb59f0e..380882f01 100644 --- a/backend/models/onboarding.py +++ b/backend/models/onboarding.py @@ -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 diff --git a/backend/repository/onboarding/get_user_onboarding.py b/backend/repository/onboarding/get_user_onboarding.py index 5eff92916..7a1f190c1 100644 --- a/backend/repository/onboarding/get_user_onboarding.py +++ b/backend/repository/onboarding/get_user_onboarding.py @@ -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 diff --git a/backend/repository/onboarding/udpate_user_onboarding.py b/backend/repository/onboarding/udpate_user_onboarding.py index d6821978f..5d7a07fed 100644 --- a/backend/repository/onboarding/udpate_user_onboarding.py +++ b/backend/repository/onboarding/udpate_user_onboarding.py @@ -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() diff --git a/backend/routes/onboarding_routes.py b/backend/routes/onboarding_routes.py index 7c2ca348c..01ee637b0 100644 --- a/backend/routes/onboarding_routes.py +++ b/backend/routes/onboarding_routes.py @@ -3,7 +3,10 @@ from auth import ( 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 @@ -18,7 +21,7 @@ onboarding_router = APIRouter() ) async def get_user_onboarding_handler( current_user: UserIdentity = Depends(get_current_user), -): +) -> GetOnboardingResponse | None: """ Get user onboarding information for the current user """ @@ -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 """ diff --git a/frontend/public/locales/en/chat.json b/frontend/public/locales/en/chat.json index 523683d14..7926d01a5 100644 --- a/frontend/public/locales/en/chat.json +++ b/frontend/public/locales/en/chat.json @@ -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 🥳", diff --git a/frontend/public/locales/es/chat.json b/frontend/public/locales/es/chat.json index e7f634380..cf225ea00 100644 --- a/frontend/public/locales/es/chat.json +++ b/frontend/public/locales/es/chat.json @@ -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 🥳", diff --git a/frontend/public/locales/fr/chat.json b/frontend/public/locales/fr/chat.json index c8089a353..67582069f 100644 --- a/frontend/public/locales/fr/chat.json +++ b/frontend/public/locales/fr/chat.json @@ -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 🥳", diff --git a/frontend/public/locales/pt-br/chat.json b/frontend/public/locales/pt-br/chat.json index fe99f8b44..fc8f1e451 100644 --- a/frontend/public/locales/pt-br/chat.json +++ b/frontend/public/locales/pt-br/chat.json @@ -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 🥳", diff --git a/frontend/public/locales/ru/chat.json b/frontend/public/locales/ru/chat.json index 72ee15706..a5a3fd31b 100644 --- a/frontend/public/locales/ru/chat.json +++ b/frontend/public/locales/ru/chat.json @@ -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":"Последний шаг 🥳", diff --git a/frontend/public/locales/zh-cn/chat.json b/frontend/public/locales/zh-cn/chat.json index b4020d1e9..e3dede5c9 100644 --- a/frontend/public/locales/zh-cn/chat.json +++ b/frontend/public/locales/zh-cn/chat.json @@ -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":"最后一步 🥳",