211 lines
8.8 KiB
Python
211 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Phase-7: file-upload (docs), search, email-stub, dashboard-widgets, mobile-polish."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import datetime
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from phase2_features import Feature, FileGen, ROOT, log, log_section # noqa: E402
|
|
from phase3_features import run_feature_v2 # noqa: E402
|
|
|
|
PHASE7_STATE = ROOT / ".phase7-state.json"
|
|
|
|
FEATURES: list[Feature] = [
|
|
Feature(
|
|
name="documents-upload",
|
|
description="File-Upload via @fastify/multipart + Documents-Page",
|
|
files=[
|
|
FileGen(
|
|
path="apps/api/src/db/schema.ts",
|
|
purpose=(
|
|
"ERWEITERT — behalte alle Tabellen. Füge `documents` (pgTable 'documents'): "
|
|
"id (uuid pk default random), userId (uuid references users id), "
|
|
"filename (text notnull), contentType (text notnull), sizeBytes (integer notnull), "
|
|
"content (bytea via customType), createdAt (timestamp default now)."
|
|
),
|
|
refs=["apps/api/src/db/schema.ts"],
|
|
),
|
|
FileGen(
|
|
path="apps/api/src/routes/documents.ts",
|
|
purpose=(
|
|
"Fastify-Plugin /api/documents. Auth required. "
|
|
"GET / (list user's docs, metadata only — kein content), "
|
|
"POST / (multipart-Upload via request.file(), speichert filename+contentType+size+content), "
|
|
"GET /:id/file (returnt content mit Content-Type header), DELETE /:id. "
|
|
"User sieht nur eigene (außer admin)."
|
|
),
|
|
refs=["apps/api/src/routes/customers.ts"],
|
|
),
|
|
FileGen(
|
|
path="apps/web/src/pages/Documents.tsx",
|
|
purpose=(
|
|
"Documents-Page. Drag-and-drop oder File-Input zum Upload. "
|
|
"Liste aller Dokumente: filename, Größe (formatiert MB), datum, Download-Link + Delete-Button. "
|
|
"Verwende api.listDocuments(), api.uploadDocument(file), api.deleteDocument(id). "
|
|
"Download via window.open(`/api/documents/${id}/file`)."
|
|
),
|
|
refs=["apps/web/src/pages/TimeEntries.tsx"],
|
|
),
|
|
],
|
|
),
|
|
Feature(
|
|
name="search-everywhere",
|
|
description="Global Search API + Search-Bar component",
|
|
files=[
|
|
FileGen(
|
|
path="apps/api/src/routes/search.ts",
|
|
purpose=(
|
|
"Fastify-Plugin /api/search?q=... Auth required. "
|
|
"Sucht in time-entries (description), customers (name), projects (name), users (email/name für admin). "
|
|
"Returns: { timeEntries, customers, projects, users? } arrays mit max 10 pro Kategorie. "
|
|
"Verwende drizzle ilike() für case-insensitive."
|
|
),
|
|
refs=["apps/api/src/routes/customers.ts"],
|
|
),
|
|
FileGen(
|
|
path="apps/web/src/components/SearchBar.tsx",
|
|
purpose=(
|
|
"Global Search-Component. Input rechts in Nav-Bar. Debounced (300ms). "
|
|
"Bei Input ≥2 chars: useQuery api.search(q). Dropdown unterhalb zeigt Resultate gruppiert. "
|
|
"Klick → navigate zur Detail-Page (z.B. /customers/$id)."
|
|
),
|
|
refs=["apps/web/src/components/CommandPalette.tsx", "apps/web/src/lib/api.ts"],
|
|
),
|
|
],
|
|
),
|
|
Feature(
|
|
name="email-notification-stub",
|
|
description="Email-Service-Stub für Notifications (console-log only, kein realer SMTP)",
|
|
files=[
|
|
FileGen(
|
|
path="apps/api/src/services/email.ts",
|
|
purpose=(
|
|
"EmailService class. Methoden: sendWelcome(user), sendPasswordReset(email, token), sendDailyReminder(user). "
|
|
"MVP: nur console.log mit formatiertem Output (subject, to, body) — kein realer SMTP, das kommt später. "
|
|
"Export const emailService = new EmailService()."
|
|
),
|
|
),
|
|
FileGen(
|
|
path="apps/api/src/routes/users.ts",
|
|
purpose=(
|
|
"ERWEITERT — behalte alles. Füge in POST / (create user, admin-only): nach Insert ruf "
|
|
"emailService.sendWelcome(newUser) auf. Import service oben."
|
|
),
|
|
refs=["apps/api/src/routes/users.ts"],
|
|
),
|
|
],
|
|
),
|
|
Feature(
|
|
name="mobile-responsive-polish",
|
|
description="Nav + Pages mobile-friendly (Hamburger, stacking)",
|
|
files=[
|
|
FileGen(
|
|
path="apps/web/src/components/Nav.tsx",
|
|
purpose=(
|
|
"ERWEITERT — Mobile-Hamburger (Menu-Icon) bei md:hidden, full Nav-Links als overlay-drawer beim Klick. "
|
|
"Desktop: bestehender flex Layout. Tailwind: md:flex vs Mobile-Menü-State (useState)."
|
|
),
|
|
refs=["apps/web/src/components/Nav.tsx"],
|
|
),
|
|
],
|
|
),
|
|
Feature(
|
|
name="api-client-phase7",
|
|
description="API um docs + search erweitert",
|
|
files=[
|
|
FileGen(
|
|
path="apps/web/src/lib/api.ts",
|
|
purpose=(
|
|
"ERWEITERT — behalte ALLES. Füge: "
|
|
"listDocuments(), uploadDocument(file: File), deleteDocument(id), "
|
|
"search(q: string)."
|
|
),
|
|
refs=["apps/web/src/lib/api.ts"],
|
|
),
|
|
],
|
|
),
|
|
Feature(
|
|
name="router-phase7",
|
|
description="App + routes/index für phase7 Routes",
|
|
files=[
|
|
FileGen(
|
|
path="apps/api/src/routes/index.ts",
|
|
purpose=(
|
|
"ERWEITERT — behalte alle. Füge documentsRoutes ('/api/documents'), searchRoutes ('/api/search')."
|
|
),
|
|
refs=["apps/api/src/routes/index.ts"],
|
|
),
|
|
FileGen(
|
|
path="apps/api/src/index.ts",
|
|
purpose=(
|
|
"ERWEITERT — behalte alles. Registriere @fastify/multipart Plugin: "
|
|
"`await server.register(import('@fastify/multipart').then(m => m.default), { limits: { fileSize: 20*1024*1024 } })`."
|
|
),
|
|
refs=["apps/api/src/index.ts"],
|
|
),
|
|
FileGen(
|
|
path="apps/web/src/App.tsx",
|
|
purpose="ERWEITERT — füge /documents (Documents Page) Route hinzu. Auth-Check.",
|
|
refs=["apps/web/src/App.tsx"],
|
|
),
|
|
],
|
|
),
|
|
]
|
|
|
|
|
|
def load_state() -> dict:
|
|
if PHASE7_STATE.exists():
|
|
return json.loads(PHASE7_STATE.read_text())
|
|
return {"completed_features": [], "current_feature": None, "started_at": datetime.datetime.now().isoformat()}
|
|
|
|
|
|
def save_state(state: dict) -> None:
|
|
PHASE7_STATE.write_text(json.dumps(state, indent=2))
|
|
|
|
|
|
async def main() -> int:
|
|
log_section("🚀 Phase-7 Codegen-Run gestartet")
|
|
|
|
# ensure @fastify/multipart is installed
|
|
import subprocess
|
|
log("Installing @fastify/multipart…")
|
|
r = subprocess.run(["pnpm", "--filter", "api", "add", "@fastify/multipart"],
|
|
cwd=ROOT, capture_output=True, text=True, timeout=120)
|
|
log(f" rc={r.returncode}: {r.stdout[-200:]}")
|
|
|
|
state = load_state()
|
|
for feature in FEATURES:
|
|
if feature.name in state.get("completed_features", []):
|
|
continue
|
|
state["current_feature"] = feature.name; save_state(state)
|
|
try:
|
|
success = await run_feature_v2(feature)
|
|
if success:
|
|
state.setdefault("completed_features", []).append(feature.name)
|
|
else:
|
|
state.setdefault("attempted_features", []).append(feature.name)
|
|
save_state(state)
|
|
except Exception as e:
|
|
log(f"❌ {feature.name} crashed: {e}", level="ERROR")
|
|
state.setdefault("attempted_features", []).append(feature.name); save_state(state)
|
|
|
|
log_section("Phase-7 Run beendet")
|
|
log(f"OK: {len(state.get('completed_features', []))}, Attempted: {len(state.get('attempted_features', []))}, Total: {len(FEATURES)}")
|
|
|
|
# auto db:generate + migrate
|
|
log("Running db:generate + db:migrate…")
|
|
r = subprocess.run(["pnpm", "--filter", "api", "db:generate"], cwd=ROOT, capture_output=True, text=True, timeout=60)
|
|
log(f" db:generate rc={r.returncode}: {r.stdout[-200:]}")
|
|
r = subprocess.run(["pnpm", "--filter", "api", "db:migrate"], cwd=ROOT, capture_output=True, text=True, timeout=60)
|
|
log(f" db:migrate rc={r.returncode}: {r.stdout[-200:]}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(asyncio.run(main()))
|