2023-06-22 18:50:06 +03:00
|
|
|
from dataclasses import dataclass
|
2023-06-28 20:39:27 +03:00
|
|
|
from uuid import UUID
|
2023-06-22 18:50:06 +03:00
|
|
|
|
2023-06-28 20:39:27 +03:00
|
|
|
from logger import get_logger
|
|
|
|
from models.chat import Chat
|
2023-08-03 21:24:42 +03:00
|
|
|
from models.settings import get_supabase_db
|
2023-06-22 18:50:06 +03:00
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class CreateChatProperties:
|
|
|
|
name: str
|
|
|
|
|
|
|
|
def __init__(self, name: str):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
|
2023-06-28 20:39:27 +03:00
|
|
|
def create_chat(user_id: UUID, chat_data: CreateChatProperties) -> Chat:
|
2023-08-03 21:24:42 +03:00
|
|
|
supabase_db = get_supabase_db()
|
2023-06-22 18:50:06 +03:00
|
|
|
|
|
|
|
# Chat is created upon the user's first question asked
|
|
|
|
logger.info(f"New chat entry in chats table for user {user_id}")
|
|
|
|
|
|
|
|
# Insert a new row into the chats table
|
|
|
|
new_chat = {
|
2023-06-28 20:39:27 +03:00
|
|
|
"user_id": str(user_id),
|
2023-06-22 18:50:06 +03:00
|
|
|
"chat_name": chat_data.name,
|
|
|
|
}
|
2023-08-03 21:24:42 +03:00
|
|
|
insert_response = supabase_db.create_chat(new_chat)
|
2023-06-22 18:50:06 +03:00
|
|
|
logger.info(f"Insert response {insert_response.data}")
|
|
|
|
|
|
|
|
return insert_response.data[0]
|