From 289af47e12054be00c65603103b11a36897de611 Mon Sep 17 00:00:00 2001 From: Sachin Mahato Date: Wed, 10 Jun 2026 13:04:01 +0530 Subject: [PATCH] feat(api): add PATCH /chat/sessions/{session_id} to rename chat sessions --- backend/app/routes/chat.py | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/backend/app/routes/chat.py b/backend/app/routes/chat.py index 00f14cc3..02f7f7c5 100644 --- a/backend/app/routes/chat.py +++ b/backend/app/routes/chat.py @@ -356,6 +356,50 @@ def rename_chat_session( return session +# ---- NEW ROUTE added for issue #434 ---- +@router.patch( + "/sessions/{session_id}", + response_model=ChatSessionResponse, + summary="Rename a chat session", + description="Updates the title of one chat session after verifying it belongs to the authenticated user.", +) +def patch_chat_session( + session_id: str, + payload: ChatSessionCreate, + user: User = Depends(get_current_user), + db: Session = Depends(get_db), +): + """Rename an existing chat session owned by the authenticated user via PATCH. + + Args: + session_id: The ID of the chat session to rename. + payload: ChatSessionCreate containing the new `title`. + user: The currently authenticated user. + db: SQLAlchemy database session. + + Returns: + ChatSessionResponse: The updated session with the new title. + + Raises: + HTTPException: 404 if the session does not exist or does not belong to the user. + """ + session = ( + db.query(ChatSession) + .filter( + ChatSession.id == session_id, + ChatSession.user_id == user.id, + ) + .first() + ) + if not session: + raise NotFoundException("Chat session") + session.title = payload.title + db.commit() + db.refresh(session) + return session +# ---- END NEW ROUTE ---- + + @router.delete( "/sessions/{session_id}", summary="Delete a chat session",