diff --git a/app/handlers.py b/app/handlers.py index 2f4ef276..ad1f1d84 100644 --- a/app/handlers.py +++ b/app/handlers.py @@ -161,7 +161,6 @@ def create_chat( if store.get_user(mid) is None: raise ApiError(400, "invalid_request", "Неизвестный участник чата") chat = store.create_chat(title, member_ids) - chat.pop("_cursor_created_at", None) return JSONResponse(chat, status_code=201) @@ -180,9 +179,7 @@ def list_chats( next_cursor = None if has_more and items: last = items[-1] - next_cursor = encode_cursor(last["_cursor_created_at"], last["id"], scope) - for item in items: - item.pop("_cursor_created_at", None) + next_cursor = encode_cursor(last["created_at"], last["id"], scope) return {"items": items, "next_cursor": next_cursor} @@ -200,7 +197,6 @@ def get_chat( chat = store.get_chat(chat_id) if chat is None: raise ApiError(404, "not_found", "Чат не найден") - chat.pop("_cursor_created_at", None) return chat @@ -218,7 +214,6 @@ def create_message( raise ApiError(404, "not_found", "Чат не найден") text = validate_create_message(body) message = store.add_message(chat_id, caller, text) - message.pop("_cursor_created_at", None) return JSONResponse(message, status_code=201) @@ -242,7 +237,5 @@ def list_messages( next_cursor = None if has_more and items: last = items[-1] - next_cursor = encode_cursor(last["_cursor_created_at"], last["id"], scope) - for item in items: - item.pop("_cursor_created_at", None) + next_cursor = encode_cursor(last["created_at"], last["id"], scope) return {"items": items, "next_cursor": next_cursor} diff --git a/app/store.py b/app/store.py index 3a4eed10..cda7ea37 100644 --- a/app/store.py +++ b/app/store.py @@ -17,7 +17,8 @@ def new_id() -> str: def _iso(dt: datetime) -> str: - return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") + """RFC 3339 UTC с суффиксом Z, микросекунды сохраняются для keyset-пагинации.""" + return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ") def _user_row(row: tuple) -> dict[str, Any]: @@ -37,8 +38,6 @@ def _chat_row(row: tuple, member_ids: list[str]) -> dict[str, Any]: "title": title, "member_ids": member_ids, "created_at": _iso(created_at), - # Полное значение для keyset-cursor; handler вырезает перед отдачей. - "_cursor_created_at": created_at.isoformat(), } @@ -50,8 +49,6 @@ def _message_row(row: tuple) -> dict[str, Any]: "sender_id": str(sender_id), "text": text, "created_at": _iso(created_at), - # Полное значение для keyset-cursor; handler вырезает перед отдачей. - "_cursor_created_at": created_at.isoformat(), }