feat: update onboarding controller and fix typo (#1333)

<img width="525" alt="Screenshot 2023-10-05 at 10 55 29"
src="https://github.com/StanGirard/quivr/assets/63923024/d7a4e7ef-e73f-46d0-8499-06c5e951f64a">


<img width="1207" alt="Screenshot 2023-10-05 at 10 49 45"
src="https://github.com/StanGirard/quivr/assets/63923024/50eba38a-b2cb-4e7d-82b1-ceca60abdad4">

https://github.com/StanGirard/quivr/issues/1328
This commit is contained in:
Mamadou DICKO 2023-10-05 11:31:26 +02:00 committed by GitHub
parent 64315d05da
commit 28ef515458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 40 additions and 32 deletions

View File

@ -21,6 +21,7 @@ from routes.explore_routes import explore_router
from routes.knowledge_routes import knowledge_router from routes.knowledge_routes import knowledge_router
from routes.misc_routes import misc_router from routes.misc_routes import misc_router
from routes.notification_routes import notification_router from routes.notification_routes import notification_router
from routes.onboarding_routes import onboarding_router
from routes.prompt_routes import prompt_router from routes.prompt_routes import prompt_router
from routes.subscription_routes import subscription_router from routes.subscription_routes import subscription_router
from routes.upload_routes import upload_router from routes.upload_routes import upload_router
@ -49,8 +50,10 @@ async def startup_event():
app.include_router(brain_router) app.include_router(brain_router)
app.include_router(chat_router) app.include_router(chat_router)
app.include_router(crawl_router) app.include_router(crawl_router)
app.include_router(onboarding_router)
app.include_router(explore_router) app.include_router(explore_router)
app.include_router(misc_router) app.include_router(misc_router)
app.include_router(upload_router) app.include_router(upload_router)
app.include_router(user_router) app.include_router(user_router)
app.include_router(api_key_router) app.include_router(api_key_router)

View File

@ -5,11 +5,11 @@ from fastapi import HTTPException
from models.databases.repository import ( from models.databases.repository import (
Repository, # Assuming you have a repository class Repository, # Assuming you have a repository class
) )
from models.onboarding import Onboardings
from pydantic import BaseModel from pydantic import BaseModel
class OnboardingUpdatableProperties(BaseModel): class OnboardingUpdatableProperties(BaseModel):
"""Properties that can be received on onboarding update""" """Properties that can be received on onboarding update"""
onboarding_b1: Optional[bool] onboarding_b1: Optional[bool]
@ -17,11 +17,19 @@ class OnboardingUpdatableProperties(BaseModel):
onboarding_b3: 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): class Onboarding(Repository):
def __init__(self, supabase_client): def __init__(self, supabase_client):
self.db = 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 Get user onboarding information by user_id
""" """
@ -33,30 +41,24 @@ class Onboarding(Repository):
.execute() .execute()
).data ).data
if not onboarding_data: if onboarding_data == []:
raise HTTPException(404, "User onboarding not found") return None
return Onboardings(**onboarding_data[0]) return GetOnboardingResponse(**onboarding_data[0])
def update_user_onboarding( def update_user_onboarding(
self, user_id: UUID, onboarding: OnboardingUpdatableProperties self, user_id: UUID, onboarding: OnboardingUpdatableProperties
) -> Onboardings: ) -> GetOnboardingResponse:
"""Update user onboarding information by user_id""" """Update user onboarding information by user_id"""
response = ( response = (
self.db.from_("onboarding") self.db.from_("onboarding")
.upsert( .update(onboarding.dict())
{ .match({"user_id": user_id})
"user_id": user_id,
"onboarding_b1": onboarding.onboarding_b1,
"onboarding_b2": onboarding.onboarding_b2,
"onboarding_b3": onboarding.onboarding_b3,
},
unique_keys=["user_id"],
)
.execute() .execute()
.data .data
) )
if not response: if not response:
raise HTTPException(404, "User onboarding not updated") raise HTTPException(404, "User onboarding not updated")
return Onboardings(**response[0])
return GetOnboardingResponse(**response[0])

View File

@ -1,10 +1,8 @@
from dataclasses import dataclass
from uuid import UUID from uuid import UUID
from pydantic import BaseModel from pydantic import BaseModel
@dataclass
class Onboardings(BaseModel): class Onboardings(BaseModel):
user_id: UUID user_id: UUID
onboarding_b1: bool onboarding_b1: bool

View File

@ -1,10 +1,10 @@
from uuid import UUID from uuid import UUID
from models.onboarding import Onboardings from models.databases.supabase.onboarding import GetOnboardingResponse
from models.settings import get_supabase_db 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 Get a user's onboarding status

View File

@ -1,13 +1,15 @@
from uuid import UUID from uuid import UUID
from models.databases.supabase.onboarding import OnboardingUpdatableProperties from models.databases.supabase.onboarding import (
from models.onboarding import Onboardings GetOnboardingResponse,
OnboardingUpdatableProperties,
)
from models.settings import get_supabase_db from models.settings import get_supabase_db
def update_user_onboarding( def update_user_onboarding(
user_id: UUID, onboarding: OnboardingUpdatableProperties user_id: UUID, onboarding: OnboardingUpdatableProperties
) -> Onboardings: ) -> GetOnboardingResponse:
"""Update user onboarding information by user_id""" """Update user onboarding information by user_id"""
supabase_db = get_supabase_db() supabase_db = get_supabase_db()

View File

@ -3,7 +3,10 @@ from auth import (
get_current_user, # Assuming you have a get_current_user function get_current_user, # Assuming you have a get_current_user function
) )
from fastapi import APIRouter, Depends 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 models.user_identity import UserIdentity
from repository.onboarding.get_user_onboarding import get_user_onboarding from repository.onboarding.get_user_onboarding import get_user_onboarding
from repository.onboarding.udpate_user_onboarding import update_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( async def get_user_onboarding_handler(
current_user: UserIdentity = Depends(get_current_user), current_user: UserIdentity = Depends(get_current_user),
): ) -> GetOnboardingResponse | None:
""" """
Get user onboarding information for the current user Get user onboarding information for the current user
""" """
@ -34,7 +37,7 @@ async def get_user_onboarding_handler(
async def update_user_onboarding_handler( async def update_user_onboarding_handler(
onboarding: OnboardingUpdatableProperties, onboarding: OnboardingUpdatableProperties,
current_user: UserIdentity = Depends(get_current_user), current_user: UserIdentity = Depends(get_current_user),
): ) -> GetOnboardingResponse:
""" """
Update user onboarding information for the current user Update user onboarding information for the current user
""" """

View File

@ -40,7 +40,7 @@
"download_message_2": "Step 1: Download “Quivr documentation”", "download_message_2": "Step 1: Download “Quivr documentation”",
"upload_message_1": "Congratulations on your first step 🥳", "upload_message_1": "Congratulations on your first step 🥳",
"upload_message_2": "Step 2: Now Drag and drop it on the chat or in the 📎", "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_quivr": "What is Quivr ?",
"what_is_brain": "What is a brain ?", "what_is_brain": "What is a brain ?",
"last_step": "Last step 🥳", "last_step": "Last step 🥳",

View File

@ -40,7 +40,7 @@
"download_message_2": "Paso 1: Descargar la documentación de “Quivr”", "download_message_2": "Paso 1: Descargar la documentación de “Quivr”",
"upload_message_1": "¡Felicidades por tu primer paso 🥳!", "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 📎", "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_quivr": "¿Qué es Quivr?",
"what_is_brain": "¿Qué es un cerebro?", "what_is_brain": "¿Qué es un cerebro?",
"last_step":"Último paso 🥳", "last_step":"Último paso 🥳",

View File

@ -40,7 +40,7 @@
"download_message_2": "Étape 1 : Téléchargez la documentation de “Quivr”", "download_message_2": "Étape 1 : Téléchargez la documentation de “Quivr”",
"upload_message_1": "Félicitations pour votre première étape 🥳!", "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 📎", "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_quivr": "Qu'est-ce que Quivr ?",
"what_is_brain": "Qu'est-ce qu'un cerveau ?", "what_is_brain": "Qu'est-ce qu'un cerveau ?",
"last_step":"Dernière étape 🥳", "last_step":"Dernière étape 🥳",

View File

@ -40,7 +40,7 @@
"download_message_2": "Passo 1: Baixe a documentação do 'Quivr'", "download_message_2": "Passo 1: Baixe a documentação do 'Quivr'",
"upload_message_1": "Parabéns pelo seu primeiro passo 🥳!", "upload_message_1": "Parabéns pelo seu primeiro passo 🥳!",
"upload_message_2": "Passo 2: Agora, arraste e solte no chat ou na 📎", "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_quivr": "O que é o Quivr?",
"what_is_brain": "O que é um cérebro?", "what_is_brain": "O que é um cérebro?",
"last_step":"Dernière étape 🥳", "last_step":"Dernière étape 🥳",

View File

@ -40,7 +40,7 @@
"download_message_2": "Шаг 1: Скачайте документацию Quivr", "download_message_2": "Шаг 1: Скачайте документацию Quivr",
"upload_message_1": "Поздравляем с первым шагом 🥳!", "upload_message_1": "Поздравляем с первым шагом 🥳!",
"upload_message_2": "Шаг 2: Теперь перетащите его в чат или в 📎", "upload_message_2": "Шаг 2: Теперь перетащите его в чат или в 📎",
"how_to_use_quivr": "Как использовать Quivr", "how_to_use_quivr": "Как использовать Quivr?",
"what_is_quivr": "Что такое Quivr?", "what_is_quivr": "Что такое Quivr?",
"what_is_brain": "Что такое мозг?", "what_is_brain": "Что такое мозг?",
"last_step":"Последний шаг 🥳", "last_step":"Последний шаг 🥳",

View File

@ -41,7 +41,7 @@
"download_message_2": "步骤 1下载“Quivr 文档”", "download_message_2": "步骤 1下载“Quivr 文档”",
"upload_message_1": "恭喜您迈出第一步 🥳!", "upload_message_1": "恭喜您迈出第一步 🥳!",
"upload_message_2": "第2步现在将其拖放到聊天框或 📎 中", "upload_message_2": "第2步现在将其拖放到聊天框或 📎 中",
"how_to_use_quivr": "如何使用Quivr", "how_to_use_quivr": "如何使用Quivr",
"what_is_quivr": "什么是Quivr", "what_is_quivr": "什么是Quivr",
"what_is_brain": "什么是大脑?", "what_is_brain": "什么是大脑?",
"last_step":"最后一步 🥳", "last_step":"最后一步 🥳",