Skip to content

Commit f38be57

Browse files
committed
copilot: list foodies restaurants API で pagination をサポートして
1 parent 03ae7fc commit f38be57

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

template_fastapi/repositories/restaurants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def _cosmos_item_to_restaurant(self, item: dict) -> Restaurant:
5757
tags=item.get("tags", []),
5858
)
5959

60-
def list_restaurants(self, limit: int = 10) -> list[Restaurant]:
61-
"""レストラン一覧を取得する"""
62-
query = f"SELECT TOP {limit} * FROM c"
60+
def list_restaurants(self, limit: int = 10, offset: int = 0) -> list[Restaurant]:
61+
"""レストラン一覧を取得する(ページネーション対応)"""
62+
query = f"SELECT * FROM c OFFSET {offset} LIMIT {limit}"
6363
items = list(self.container.query_items(query=query, enable_cross_partition_query=True))
6464
return [self._cosmos_item_to_restaurant(item) for item in items]
6565

template_fastapi/routers/foodies.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
tags=["foodies"],
1414
operation_id="list_foodies_restaurants",
1515
)
16-
async def list_foodies_restaurants(limit: int = Query(10, description="取得する最大件数")) -> list[Restaurant]:
16+
async def list_foodies_restaurants(
17+
limit: int = Query(10, description="取得する最大件数"),
18+
offset: int = Query(0, description="スキップする件数(ページネーション用)"),
19+
) -> list[Restaurant]:
1720
"""
18-
レストラン一覧を取得する
21+
レストラン一覧を取得する(ページネーション対応)
1922
"""
2023
try:
21-
return restaurant_repo.list_restaurants(limit)
24+
return restaurant_repo.list_restaurants(limit, offset)
2225
except Exception as e:
2326
raise HTTPException(status_code=500, detail=f"データの取得に失敗しました: {str(e)}")
2427

0 commit comments

Comments
 (0)