chore: update code styles

This commit is contained in:
Christopher Gondek 2025-10-08 15:53:15 +02:00
parent a08bd3ef1d
commit ed3920f9f9
2 changed files with 20 additions and 20 deletions

View file

@ -24,11 +24,11 @@ class UserThreadMapping(Base):
Thread_id is unique in the table. 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) id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
userId: Mapped[str] = mapped_column(String(255), nullable=False) user_id: Mapped[str] = mapped_column(String(255), nullable=False)
threadId: Mapped[str] = mapped_column(String(255), unique=True, nullable=False) thread_id: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
threadName: Mapped[str] = mapped_column(String(255), nullable=False) thread_name: Mapped[str] = mapped_column(String(255), nullable=False)
date_created: Mapped[datetime] = mapped_column( date_created: Mapped[datetime] = mapped_column(
DateTime(timezone=True), DateTime(timezone=True),
nullable=False, nullable=False,

View file

@ -46,7 +46,7 @@ async def get_all_threads_for_user(
# Query all threads for this user, ordered by date_updated descending # Query all threads for this user, ordered by date_updated descending
stmt = ( stmt = (
select(UserThreadMapping) select(UserThreadMapping)
.where(UserThreadMapping.userId == user.id) .where(UserThreadMapping.user_id == user.id)
.order_by(UserThreadMapping.date_updated.desc()) .order_by(UserThreadMapping.date_updated.desc())
) )
result = await session.execute(stmt) result = await session.execute(stmt)
@ -56,8 +56,8 @@ async def get_all_threads_for_user(
threads = [] threads = []
for mapping in thread_mappings: for mapping in thread_mappings:
thread_summary = ThreadSummary( thread_summary = ThreadSummary(
thread_id=mapping.threadId, thread_id=mapping.thread_id,
thread_name=mapping.threadName, thread_name=mapping.thread_name,
date_created=mapping.date_created.timestamp(), date_created=mapping.date_created.timestamp(),
date_updated=mapping.date_updated.timestamp(), date_updated=mapping.date_updated.timestamp(),
) )
@ -86,9 +86,9 @@ async def save_thread_for_user(
# Create new mapping entry # Create new mapping entry
new_mapping = UserThreadMapping( new_mapping = UserThreadMapping(
userId=user.id, user_id=user.id,
threadId=thread_id, thread_id=thread_id,
threadName=thread_name, thread_name=thread_name,
) )
session.add(new_mapping) session.add(new_mapping)
@ -170,7 +170,7 @@ async def assure_thread_exists_and_belongs_to_user(
ValueError: If the thread does not exist. ValueError: If the thread does not exist.
""" """
# Query the database for the thread mapping # 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) result = await session.execute(stmt)
thread_mapping = result.scalar_one_or_none() 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") raise ValueError(f"Thread {thread_id} does not exist")
# Check if thread belongs to the user # Check if thread belongs to the user
if thread_mapping.userId != user.id: if thread_mapping.user_id != user.id:
logger.warning( logger.warning(
f"User {user.id} attempted to access thread {thread_id} " 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( raise PermissionError(
f"You do not have permission to access thread {thread_id}" 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 # 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 = ( stmt = (
update(UserThreadMapping) update(UserThreadMapping)
.where( .where(
UserThreadMapping.threadId == thread_id, UserThreadMapping.thread_id == thread_id,
UserThreadMapping.userId == user.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) result = await session.execute(stmt)
await session.commit() 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}") logger.info(f"Refreshing date_updated for thread {thread_id} for user {user.id}")
# Update the date_updated timestamp # 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 = ( stmt = (
update(UserThreadMapping) update(UserThreadMapping)
.where( .where(
UserThreadMapping.threadId == thread_id, UserThreadMapping.thread_id == thread_id,
UserThreadMapping.userId == user.id, UserThreadMapping.user_id == user.id,
) )
.values(date_updated=datetime.now(timezone.utc)) .values(date_updated=datetime.now(timezone.utc))
) )