35 lines
903 B
Python
35 lines
903 B
Python
from datetime import datetime
|
||
|
||
|
||
def iso_z(dt: datetime) -> str:
|
||
"""RFC3339 UTC с 'Z'. Postgres отдаёт timestamptz с '+00:00'."""
|
||
return dt.isoformat().replace("+00:00", "Z")
|
||
|
||
|
||
def row_to_user(row) -> dict:
|
||
return {
|
||
"id": str(row["id"]),
|
||
"username": row["username"],
|
||
"display_name": row["display_name"],
|
||
"created_at": iso_z(row["created_at"]),
|
||
}
|
||
|
||
|
||
def row_to_chat(row) -> dict:
|
||
return {
|
||
"id": str(row["id"]),
|
||
"title": row["title"],
|
||
"member_ids": row["member_ids"],
|
||
"created_at": iso_z(row["created_at"]),
|
||
}
|
||
|
||
|
||
def row_to_message(row) -> dict:
|
||
return {
|
||
"id": str(row["id"]),
|
||
"chat_id": str(row["chat_id"]),
|
||
"sender_id": str(row["sender_id"]),
|
||
"text": row["text"],
|
||
"created_at": iso_z(row["created_at"]),
|
||
"attachment_ids": row.get("attachment_ids", []),
|
||
} |