- Add FastAPI app with CORS and auth middleware (Bearer token) - Add POST /api/v1/transactions/upload endpoint (multipart/form-data) - Add MinIO storage service with date-partitioned object keys - Add PostgreSQL database service for transaction metadata - Add Dockerfile and docker-compose.yml for deployment - Add config.example.yaml template Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30 lines
863 B
Python
30 lines
863 B
Python
import psycopg
|
|
from psycopg.rows import dict_row
|
|
|
|
from app.config import settings
|
|
|
|
|
|
def _get_conn():
|
|
return psycopg.connect(settings.postgresql.dsn, row_factory=dict_row)
|
|
|
|
|
|
def insert_transaction(
|
|
image_object_key: str,
|
|
original_filename: str | None,
|
|
user_note: str | None,
|
|
) -> dict:
|
|
with _get_conn() as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute(
|
|
"""
|
|
INSERT INTO transactions
|
|
(image_object_key, original_filename, user_note, process_status)
|
|
VALUES (%s, %s, %s, 'PENDING')
|
|
RETURNING id, upload_time
|
|
""",
|
|
(image_object_key, original_filename, user_note),
|
|
)
|
|
row = cur.fetchone()
|
|
conn.commit()
|
|
return {"id": str(row["id"]), "upload_time": row["upload_time"].isoformat()}
|