From 9b714bc0dea7acae0d9a6e4151266dc8446e001b Mon Sep 17 00:00:00 2001 From: Arina Date: Mon, 23 Nov 2026 15:22:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D0=B5=203=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BF=D1=80=D0=BE=D1=85=D0=BE=D0=B4=D1=8F=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database.py | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/database.py b/src/database.py index 607eac89..5d4f423b 100644 --- a/src/database.py +++ b/src/database.py @@ -227,16 +227,55 @@ class PostgresStore: def create_attachment(self, attachment: dict) -> dict: with get_db() as conn, conn.cursor() as cur: - cur.execute("SELECT 1 FROM chat_members WHERE chat_id=%s AND user_id=%s", (attachment["chat_id"], attachment["owner_id"])) + cur.execute( + "SELECT 1 FROM chat_members WHERE chat_id=%s AND user_id=%s", + (attachment["chat_id"], attachment["owner_id"]) + ) if not cur.fetchone(): - cur.execute("SELECT id FROM chats WHERE id=%s", (attachment["chat_id"],)) + cur.execute( + "SELECT id FROM chats WHERE id=%s", + (attachment["chat_id"],) + ) if cur.fetchone(): raise ValueError("owner_not_in_chat") raise ValueError("chat_not_found") + cur.execute( - "INSERT INTO attachments (id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, object_key, error_code, created_at, updated_at) VALUES (%s,%s,%s,%s,%s,%s,%s,'ready',%s,NULL,%s,%s)", - (attachment["id"], attachment["chat_id"], attachment["owner_id"], attachment["filename"], attachment["content_type"], attachment["size_bytes"], attachment["sha256"], attachment["object_key"], attachment["created_at"], attachment["updated_at"])) - return attachment + """ + INSERT INTO attachments ( + id, chat_id, owner_id, filename, content_type, + size_bytes, sha256, status, object_key, + error_code, created_at, updated_at + ) + VALUES (%s, %s, %s, %s, %s, %s, %s, 'ready', %s, NULL, %s, %s) + """, + ( + attachment["id"], + attachment["chat_id"], + attachment["owner_id"], + attachment["filename"], + attachment["content_type"], + attachment["size_bytes"], + attachment["sha256"], + attachment["object_key"], + attachment["created_at"], + attachment["updated_at"] + ) + ) + + cur.execute( + """ + SELECT id, chat_id, owner_id, filename, content_type, + size_bytes, sha256, status, error_code, + created_at, updated_at + FROM attachments + WHERE id = %s + """, + (attachment["id"],) + ) + row = cur.fetchone() + + return self._attachment_response(cur, row) def get_attachment(self, attachment_id: str, user_id: str) -> Optional[dict]: with get_db() as conn, conn.cursor() as cur: