From ed3920f9f91d3143ce3684cdb5e6117663d92e29 Mon Sep 17 00:00:00 2001 From: Christopher Gondek Date: Wed, 8 Oct 2025 15:53:15 +0200 Subject: [PATCH] chore: update code styles --- modules/features/chatBot/database.py | 8 +++---- modules/features/chatBot/service.py | 32 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/modules/features/chatBot/database.py b/modules/features/chatBot/database.py index 50dc9bba..5473fa0f 100644 --- a/modules/features/chatBot/database.py +++ b/modules/features/chatBot/database.py @@ -24,11 +24,11 @@ class UserThreadMapping(Base): Thread_id is unique in the table. """ - __tablename__ = "userThreads" + __tablename__ = "user_threads" id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4) - userId: Mapped[str] = mapped_column(String(255), nullable=False) - threadId: Mapped[str] = mapped_column(String(255), unique=True, nullable=False) - threadName: Mapped[str] = mapped_column(String(255), nullable=False) + user_id: Mapped[str] = mapped_column(String(255), nullable=False) + thread_id: Mapped[str] = mapped_column(String(255), unique=True, nullable=False) + thread_name: Mapped[str] = mapped_column(String(255), nullable=False) date_created: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, diff --git a/modules/features/chatBot/service.py b/modules/features/chatBot/service.py index 3060081d..ef3252e9 100644 --- a/modules/features/chatBot/service.py +++ b/modules/features/chatBot/service.py @@ -46,7 +46,7 @@ async def get_all_threads_for_user( # Query all threads for this user, ordered by date_updated descending stmt = ( select(UserThreadMapping) - .where(UserThreadMapping.userId == user.id) + .where(UserThreadMapping.user_id == user.id) .order_by(UserThreadMapping.date_updated.desc()) ) result = await session.execute(stmt) @@ -56,8 +56,8 @@ async def get_all_threads_for_user( threads = [] for mapping in thread_mappings: thread_summary = ThreadSummary( - thread_id=mapping.threadId, - thread_name=mapping.threadName, + thread_id=mapping.thread_id, + thread_name=mapping.thread_name, date_created=mapping.date_created.timestamp(), date_updated=mapping.date_updated.timestamp(), ) @@ -86,9 +86,9 @@ async def save_thread_for_user( # Create new mapping entry new_mapping = UserThreadMapping( - userId=user.id, - threadId=thread_id, - threadName=thread_name, + user_id=user.id, + thread_id=thread_id, + thread_name=thread_name, ) session.add(new_mapping) @@ -170,7 +170,7 @@ async def assure_thread_exists_and_belongs_to_user( ValueError: If the thread does not exist. """ # Query the database for the thread mapping - stmt = select(UserThreadMapping).where(UserThreadMapping.threadId == thread_id) + stmt = select(UserThreadMapping).where(UserThreadMapping.thread_id == thread_id) result = await session.execute(stmt) thread_mapping = result.scalar_one_or_none() @@ -180,10 +180,10 @@ async def assure_thread_exists_and_belongs_to_user( raise ValueError(f"Thread {thread_id} does not exist") # Check if thread belongs to the user - if thread_mapping.userId != user.id: + if thread_mapping.user_id != user.id: logger.warning( f"User {user.id} attempted to access thread {thread_id} " - f"belonging to user {thread_mapping.userId}" + f"belonging to user {thread_mapping.user_id}" ) raise PermissionError( f"You do not have permission to access thread {thread_id}" @@ -219,14 +219,14 @@ async def update_thread_name( ) # Update the thread name and date_updated - # Security check: WHERE clause includes both threadId AND userId + # Security check: WHERE clause includes both thread_id AND user_id stmt = ( update(UserThreadMapping) .where( - UserThreadMapping.threadId == thread_id, - UserThreadMapping.userId == user.id, + UserThreadMapping.thread_id == thread_id, + UserThreadMapping.user_id == user.id, ) - .values(threadName=new_thread_name, date_updated=datetime.now(timezone.utc)) + .values(thread_name=new_thread_name, date_updated=datetime.now(timezone.utc)) ) result = await session.execute(stmt) await session.commit() @@ -267,12 +267,12 @@ async def refresh_thread_date_updated( logger.info(f"Refreshing date_updated for thread {thread_id} for user {user.id}") # Update the date_updated timestamp - # Security check: WHERE clause includes both threadId AND userId + # Security check: WHERE clause includes both thread_id AND user_id stmt = ( update(UserThreadMapping) .where( - UserThreadMapping.threadId == thread_id, - UserThreadMapping.userId == user.id, + UserThreadMapping.thread_id == thread_id, + UserThreadMapping.user_id == user.id, ) .values(date_updated=datetime.now(timezone.utc)) )