Skip to content

Commit d9aa28b

Browse files
Merge pull request #46 from 9git9git/hotfix
🩹 카테고리 id 안받는 부분 수정 및 chat endpoints 정리
2 parents cf534f5 + a41de4e commit d9aa28b

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

app/api/v1/endpoints/chat.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
router = APIRouter()
2020

2121

22-
@router.get("/", response_model=ResponseBase[List[ChatResponse]])
22+
@router.get("/all", response_model=ResponseBase[List[ChatResponse]])
2323
async def get_chats_by_user(
2424
user_id: UUID,
2525
db: AsyncSession = Depends(get_db),
@@ -35,31 +35,16 @@ async def get_chats_by_user(
3535
)
3636

3737

38-
@router.get("/storage/{storage_id}", response_model=ResponseBase[List[ChatResponse]])
39-
async def get_chats_by_storage(
40-
user_id: UUID,
41-
storage_id: UUID,
42-
db: AsyncSession = Depends(get_db),
43-
) -> ResponseBase[List[ChatResponse]]:
44-
try:
45-
chats = await select_chats_by_storage(db, user_id, storage_id)
46-
return ResponseBase(status_code=status.HTTP_200_OK, data=chats)
47-
except HTTPException as e:
48-
return ResponseBase(status_code=e.status_code, error=e.detail)
49-
except Exception as e:
50-
return ResponseBase(
51-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, error=str(e)
52-
)
53-
54-
5538
@router.get("/", response_model=ResponseBase[List[ChatResponse]])
56-
async def get_chats_by_category(
39+
async def get_chats_by_storage_and_category(
5740
user_id: UUID,
41+
storage_id: UUID,
5842
category_id: UUID,
5943
db: AsyncSession = Depends(get_db),
6044
) -> ResponseBase[List[ChatResponse]]:
6145
try:
62-
chats = await select_chats_by_category(db, user_id, category_id)
46+
# 스토리지 ID 기준으로 조회 (storage_id가 URL 접두사에 이미 포함되어 있음)
47+
chats = await select_chats_by_storage(db, user_id, storage_id, category_id)
6348
return ResponseBase(status_code=status.HTTP_200_OK, data=chats)
6449
except HTTPException as e:
6550
return ResponseBase(status_code=e.status_code, error=e.detail)

app/api/v1/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
)
5757
router.include_router(
5858
chat.router,
59-
prefix="/users/{user_id}/categories/{category_id}/chats",
59+
prefix="/users/{user_id}/categories/{category_id}/storages/{storage_id}/chats",
6060
tags=["chats"],
6161
)
6262
router.include_router(

app/crud/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,14 @@ async def read_chats_by_storage(
110110
db: AsyncSession,
111111
user_id: UUID,
112112
storage_id: UUID,
113+
category_id: UUID,
113114
) -> List[ChatResponse]:
114115
result = await db.execute(
115-
select(Chat).where(Chat.user_id == user_id, Chat.storage_id == storage_id)
116+
select(Chat).where(
117+
Chat.user_id == user_id,
118+
Chat.storage_id == storage_id,
119+
Chat.category_id == category_id,
120+
)
116121
)
117122
return result.scalars().all()
118123

app/schemas/chat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ChatResponse(BaseModel):
1919
category_id: UUID
2020
role: RoleEnum
2121
content: str
22+
created_at: datetime
2223

2324

2425
class ModelResponse(BaseModel):

app/services/chat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ async def select_chats_by_storage(
4343
db: AsyncSession,
4444
user_id: UUID,
4545
storage_id: UUID,
46+
category_id: UUID,
4647
) -> List[ChatResponse]:
47-
return await read_chats_by_storage(db, user_id, storage_id)
48+
return await read_chats_by_storage(db, user_id, storage_id, category_id)
4849

4950

5051
# category_id 기준 조회

0 commit comments

Comments
 (0)