feat(api): customer filters user_id / add_time_since / last_chat_since
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"""GET /api/customers — paginated, filterable customer list.
|
||||
|
||||
Read-only query over the mirrored ``customer`` table. Supports filtering by
|
||||
``channel``, ``owner_account_id`` (direct columns) and ``department_id``
|
||||
(resolved through ``customer.user_id`` -> ``staff.dept_id``). Results are
|
||||
ordered by ``last_chat_time desc`` (nulls last) then ``friend_id`` so the
|
||||
``channel``, ``owner_account_id``, ``user_id``, ``add_time_since`` and
|
||||
``last_chat_since`` (direct columns) and ``department_id`` (resolved through
|
||||
``customer.user_id`` -> ``staff.dept_id``). Results are ordered by
|
||||
``last_chat_time desc`` (nulls last) then ``friend_id`` so the
|
||||
most-recently-active contacts surface first.
|
||||
"""
|
||||
|
||||
@@ -34,6 +35,9 @@ async def list_customers(
|
||||
channel: Annotated[str | None, Query()] = None,
|
||||
department_id: Annotated[str | None, Query()] = None,
|
||||
owner_account_id: Annotated[str | None, Query()] = None,
|
||||
user_id: Annotated[str | None, Query()] = None,
|
||||
add_time_since: Annotated[int | None, Query(ge=0)] = None,
|
||||
last_chat_since: Annotated[int | None, Query(ge=0)] = None,
|
||||
) -> Page[CustomerOut]:
|
||||
"""List customers with optional filters and pagination."""
|
||||
conditions = []
|
||||
@@ -47,6 +51,12 @@ async def list_customers(
|
||||
Staff.dept_id == department_id
|
||||
)
|
||||
conditions.append(Customer.user_id.in_(dept_user_ids))
|
||||
if user_id is not None:
|
||||
conditions.append(Customer.user_id == user_id)
|
||||
if add_time_since is not None:
|
||||
conditions.append(Customer.add_time >= add_time_since)
|
||||
if last_chat_since is not None:
|
||||
conditions.append(Customer.last_chat_time >= last_chat_since)
|
||||
|
||||
total_stmt = sa.select(sa.func.count()).select_from(Customer)
|
||||
if conditions:
|
||||
|
||||
Reference in New Issue
Block a user