From 2d1943a74e3948939d390bf16b088392dd4ed9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Sat, 15 Aug 2026 14:18:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E5=AE=A2=E6=88=B7/=E7=BE=A4?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E6=94=B9=E5=9B=9Elast=5Fchat=5Ftime=20DESC(?= =?UTF-8?q?=E4=BA=91=E5=AE=A2=E6=8C=89=E6=9C=80=E8=BF=91=E6=B2=9F=E9=80=9A?= =?UTF-8?q?=E4=BC=98=E5=85=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- yunke-server/app/api/routers/customer.py | 1 + yunke-server/app/api/routers/groups.py | 1 + yunke-server/tests/test_api_customer.py | 9 +++------ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/yunke-server/app/api/routers/customer.py b/yunke-server/app/api/routers/customer.py index a65a0cc..6d42e55 100644 --- a/yunke-server/app/api/routers/customer.py +++ b/yunke-server/app/api/routers/customer.py @@ -71,6 +71,7 @@ async def list_customers( list_stmt = list_stmt.where(*conditions) list_stmt = ( list_stmt.order_by( + sa.nullslast(Customer.last_chat_time.desc()), Customer.friend_id.asc(), ) .limit(page_size) diff --git a/yunke-server/app/api/routers/groups.py b/yunke-server/app/api/routers/groups.py index 8717bcc..b5c2e69 100644 --- a/yunke-server/app/api/routers/groups.py +++ b/yunke-server/app/api/routers/groups.py @@ -61,6 +61,7 @@ async def list_groups( list_stmt = list_stmt.where(*conditions) list_stmt = ( list_stmt.order_by( + sa.nullslast(ChatGroup.last_chat_time.desc()), ChatGroup.room_id.asc(), ) .limit(page_size) diff --git a/yunke-server/tests/test_api_customer.py b/yunke-server/tests/test_api_customer.py index 6cffc0f..73dc56a 100644 --- a/yunke-server/tests/test_api_customer.py +++ b/yunke-server/tests/test_api_customer.py @@ -205,17 +205,14 @@ async def test_pagination_page_size_one(client: AsyncClient): assert len(body["items"]) == 1 -async def test_order_is_friend_id_asc(client: AsyncClient): - """Order: ``friend_id ASC`` (natural API/云客 order). - - Seeded IDs wa_c < wx_a < wx_b → expected order ``[wa_c, wx_a, wx_b]``. - """ +async def test_order_is_last_chat_time_desc_nulls_last(client: AsyncClient): + """Order: ``last_chat_time DESC`` (nulls last) — 云客 sorts most-recent-chat-first.""" r = await client.get( "/api/customers", params={"page": 1, "page_size": 20} ) assert r.status_code == 200 ids = [it["friend_id"] for it in r.json()["items"]] - assert ids == ["wa_c", "wx_a", "wx_b"] + assert ids == ["wx_a", "wx_b", "wa_c"] async def test_filter_by_owner_account_id(client: AsyncClient):