Implement Phase 1 backend: FastAPI upload API with MinIO and PostgreSQL

- 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>
This commit is contained in:
Misaka_Company
2026-05-21 16:42:08 +08:00
parent a7ae5cba5d
commit e3c84540eb
16 changed files with 306 additions and 0 deletions

29
app/services/database.py Normal file
View File

@@ -0,0 +1,29 @@
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()}