forked from mtusi2026/mtusi2026lab4
все 3 теста проходят
This commit is contained in:
+44
-5
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user