feat(backend): 无界列表端点加分页——projects/templates 支持 limit/offset
GET /projects 与 GET /templates 原一次返回全部 owner 行,行数随数据线性增长。 新增可复用分页依赖 ww_api.pagination.get_page(limit∈[1,200] 默认 50、offset≥0, 越界 → 422),两端点接入,Repository.list_for_owner 加 keyword-only limit/offset 把 LIMIT/OFFSET 下推 DB。向后兼容:不传参返回第一页。补 projects 分页 + 边界 422 测试。
This commit is contained in:
@@ -38,8 +38,13 @@ class _FakeTemplateRepo:
|
||||
self.flushed += 1
|
||||
return view
|
||||
|
||||
async def list_for_owner(self, owner_id: uuid.UUID) -> list[TemplateView]:
|
||||
return [v for tid, v in self.rows.items() if self.owners[tid] == owner_id]
|
||||
async def list_for_owner(
|
||||
self, owner_id: uuid.UUID, *, limit: int | None = None, offset: int = 0
|
||||
) -> list[TemplateView]:
|
||||
views = [v for tid, v in self.rows.items() if self.owners[tid] == owner_id]
|
||||
if limit is None:
|
||||
return views
|
||||
return views[offset : offset + limit]
|
||||
|
||||
async def delete(self, owner_id: uuid.UUID, template_id: uuid.UUID) -> bool:
|
||||
if self.rows.get(template_id) is None or self.owners.get(template_id) != owner_id:
|
||||
|
||||
Reference in New Issue
Block a user