fix(groups): /api/groups加room_id精确直查(群聊页群名解析,修page_size=200超限422)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-20 10:58:39 +08:00
parent 1d90829754
commit 6c9245a682
4 changed files with 32 additions and 6 deletions
+6 -2
View File
@@ -35,19 +35,23 @@ async def list_groups(
channel: Annotated[str | None, Query()] = None,
owner_account_id: Annotated[str | None, Query()] = None,
user_id: Annotated[str | None, Query()] = None,
room_id: Annotated[str | None, Query()] = None,
) -> Page[GroupOut]:
"""List chat groups with optional ``channel`` / ``owner_account_id`` /
``user_id`` filters.
``user_id`` / ``room_id`` filters.
``user_id`` maps to the ``ChatGroup.owner_user_id`` column (the staff
``userId`` who owns the chatroom account), mirroring the ``user_id``
filter on ``GET /api/customers``.
filter on ``GET /api/customers``. ``room_id`` is an exact-match single-
row lookup (chat page group-name resolution).
"""
conditions = []
if channel is not None:
conditions.append(ChatGroup.channel == channel)
if owner_account_id is not None:
conditions.append(ChatGroup.owner_account_id == owner_account_id)
if room_id is not None:
conditions.append(ChatGroup.room_id == room_id)
if user_id is not None:
conditions.append(ChatGroup.owner_user_id == user_id)
+20
View File
@@ -235,3 +235,23 @@ async def test_members_empty_room_is_200(make_client):
r = await client.get("/api/groups/room_b@chatroom/members")
assert r.status_code == 200
assert r.json() == []
# ---------------------------------------------------------------------------
# room_id 精确过滤(2026-08-20:群聊页群名单行直查,替代超上限的大页拉取)
# ---------------------------------------------------------------------------
async def test_room_id_filter_returns_single_group(make_client):
async def seed(session):
session.add_all([
ChatGroup(room_id="r1@chatroom", channel="wechat", room_name="群一", owner_account_id="o1"),
ChatGroup(room_id="r2@chatroom", channel="wechat", room_name="群二", owner_account_id="o1"),
])
await session.commit()
client = await make_client(seed)
r = await client.get("/api/groups", params={"room_id": "r2@chatroom"})
assert r.status_code == 200
body = r.json()
assert body["total"] == 1
assert body["items"][0]["room_name"] == "群二"