Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/api/chat_tab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions app/core/enum/db_key_prefix_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class DBSaveIdEnum(Enum):
user_db = "USER-DB"
driver = "DRIVER"
api_key = "API-KEY"
chat_tab = "CHAT_TAB"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스타일 일치를 위해 구분자는 underscore(_) 보다는 hyphen(-)이 더 나을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

허걱~ 숲을 안보고 나무만봤네요. 꼼꼼히 봐주셔서 감사합니다. 수정하겠습니다.

5 changes: 4 additions & 1 deletion app/core/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """

Expand Down
15 changes: 15 additions & 0 deletions app/repository/chat_tab_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 9 additions & 1 deletion app/services/chat_tab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down Expand Up @@ -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()