diff --git a/app/api/chat_tab_api.py b/app/api/chat_tab_api.py index cc73197..e5cb938 100644 --- a/app/api/chat_tab_api.py +++ b/app/api/chat_tab_api.py @@ -75,3 +75,28 @@ def delete_chat_tab( """ service.delete_chat_tab(tabId) return ResponseMessage.success(code=CommonCode.SUCCESS_CHAT_TAB_DELETE) + +@router.get( + "/result", + response_model=ResponseMessage[list[ChatTabResponse]], + summary="저장된 모든 Chat_tab 정보 조회", + description=""" + chat_tab 테이블에 저장된 모든 chat tab들을 확인합니다. + """, +) +def get_all_chat_tab( + service: ChatTabService = chat_tab_service_dependency, +) -> ResponseMessage[list[ChatTabResponse]]: + """저장된 모든 chat_tab의 메타데이터를 조회하여 등록 여부를 확인합니다.""" + chat_tabs_in_db = service.get_all_chat_tab() + + response_data = [ + ChatTabResponse( + id=chat_tab.id, + name=chat_tab.name, + created_at=chat_tab.created_at, + updated_at=chat_tab.updated_at, + ) + for chat_tab in chat_tabs_in_db + ] + return ResponseMessage.success(value=response_data, code=CommonCode.SUCCESS_GET_CHAT_TAB) diff --git a/app/core/enum/db_key_prefix_name.py b/app/core/enum/db_key_prefix_name.py index 859ed2f..b10b72c 100644 --- a/app/core/enum/db_key_prefix_name.py +++ b/app/core/enum/db_key_prefix_name.py @@ -8,3 +8,4 @@ class DBSaveIdEnum(Enum): user_db = "USER-DB" driver = "DRIVER" api_key = "API-KEY" + chat_tab = "CHAT_TAB" \ No newline at end of file diff --git a/app/core/status.py b/app/core/status.py index ce25f6a..7d68f56 100644 --- a/app/core/status.py +++ b/app/core/status.py @@ -35,7 +35,10 @@ class CommonCode(Enum): SUCCESS_GET_API_KEY = (status.HTTP_200_OK, "2202", "API KEY 정보를 성공적으로 조회했습니다.") """ AI CHAT, DB 성공 코드 - 23xx """ - SUCCESS_AI_CHAT_CREATE = (status.HTTP_200_OK, "2300", "새로운 채팅 탭을 생성하였습니다.") + SUCCESS_CHAT_TAB_CREATE = (status.HTTP_200_OK, "2300", "새로운 채팅 탭이 성공적으로 생성하였습니다.") + SUCCESS_CHAT_TAB_UPDATE = (status.HTTP_200_OK, "2301", "채팅 탭 이름이 성공적으로 수정되었습니다.") + SUCCESS_CHAT_TAB_DELETE = (status.HTTP_200_OK, "2302", "채팅 탭을 성공적으로 삭제되었습니다.") + SUCCESS_GET_CHAT_TAB = (status.HTTP_200_OK, "2303", "모든 채팅 탭을 성공적으로 조회하였습니다.") """ ANNOTATION 성공 코드 - 24xx """ diff --git a/app/repository/chat_tab_repository.py b/app/repository/chat_tab_repository.py index d3665ca..18dea38 100644 --- a/app/repository/chat_tab_repository.py +++ b/app/repository/chat_tab_repository.py @@ -98,6 +98,21 @@ def delete_chat_tab(self, id: str) -> bool: finally: if conn: conn.close() + def get_all_chat_tab(self) -> list[ChatTabInDB]: + """데이터베이스에 저장된 모든 API Key를 조회합니다.""" + db_path = get_db_path() + conn = None + try: + conn = sqlite3.connect(str(db_path), timeout=10) + conn.row_factory = sqlite3.Row + cursor = conn.cursor() + + cursor.execute("SELECT * FROM chat_tab") + rows = cursor.fetchall() + return [ChatTabInDB.model_validate(dict(row)) for row in rows] + finally: + if conn: + conn.close() chat_tab_repository = ChatTabRepository() diff --git a/app/services/chat_tab_service.py b/app/services/chat_tab_service.py index fee44ac..685bc93 100644 --- a/app/services/chat_tab_service.py +++ b/app/services/chat_tab_service.py @@ -10,6 +10,7 @@ from app.schemas.chat_tab.db_model import ChatTabInDB from app.schemas.chat_tab.update_model import ChatTabUpdate from app.schemas.chat_tab.validation_utils import validate_chat_tab_name +from app.core.enum.db_key_prefix_name import DBSaveIdEnum chat_tab_repository_dependency = Depends(lambda: chat_tab_repository) @@ -22,7 +23,7 @@ def store_chat_tab(self, chatName: ChatTabCreate) -> ChatTabInDB: """새로운 AI 채팅을 데이터베이스에 저장합니다.""" validate_chat_tab_name(chatName.name) - new_id = generate_prefixed_uuid("CHAT_TAB") + new_id = generate_prefixed_uuid(DBSaveIdEnum.chat_tab.value) try: created_row = self.repository.create_chat_tab( @@ -66,4 +67,11 @@ def delete_chat_tab(self, tabId: str) -> None: raise APIException(CommonCode.DB_BUSY) from e raise APIException(CommonCode.FAIL) from e + def get_all_chat_tab(self) -> list[ChatTabInDB]: + """데이터베이스에 저장된 모든 Chat_tab을 조회합니다.""" + try: + return self.repository.get_all_chat_tab() + except sqlite3.Error as e: + raise APIException(CommonCode.FAIL) from e + chat_tab_service = ChatTabService()