Commit Graph

30 Commits

Author SHA1 Message Date
0797a8f55c fix: export endpoints now include auth headers
All checks were successful
Deploy Development / deploy (push) Successful in 58s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
Changed from window.open() to fetch() + Blob download.
window.open() cannot send custom headers, causing 401 errors.

**Changed:**
- exportZip: fetch with auth, download blob as .zip
- exportJson: fetch with auth, download blob as .json
- exportCsv: fetch with auth, download blob as .csv

All exports now work with authenticated sessions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:00:35 +01:00
47a268f426 fix: comprehensive PostgreSQL Decimal handling across all endpoints
All checks were successful
Deploy Development / deploy (push) Successful in 55s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
Fixed all remaining Decimal → float conversion issues found by audit.

**Fixed Endpoints:**
1. Weight Stats: min/max/avg calculations
2. Activity Stats: kcal/duration accumulation
3. Nutrition Weekly: average calculations
4. Template Variables: all f-string Decimal formatting
5. CSV Export: all numeric value formatting
6. JSON Export: added Decimal handler
7. ZIP Export: added Decimal handler
8. Correlations: weight, nutrition, caliper values

**Changes:**
- Added `from decimal import Decimal` import
- Weight stats: convert to float for min/max/avg
- Activity: float() in sum() and accumulation
- Nutrition: float() in averages
- Template vars: float() for weight_aktuell, kf_aktuell, goals
- CSV: float() in all f-strings (weight, circ, caliper, nutrition, activity)
- JSON/ZIP: custom decimal_handler for json.dumps()
- Correlations: float() for all numeric DB values

Prevents:
- TypeError in math operations
- "Decimal('X')" strings in exports
- JSON serialization failures

All numeric values from PostgreSQL now properly converted to float.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 21:52:57 +01:00
f7f7f745b1 fix: convert PostgreSQL Decimal to float for math operations
All checks were successful
Deploy Development / deploy (push) Successful in 59s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
Fixed TypeError when preparing AI prompt template variables.
PostgreSQL returns NUMERIC columns as decimal.Decimal, not float.

**Fixed in _prepare_template_vars:**
- Weight calculations (protein targets, delta)
- Nutrition averages (kcal, protein, fat, carbs)
- Activity totals (kcal_active)

All Decimal values now converted to float before math operations.

Error was: "TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 21:44:10 +01:00
8e25b54cc2 docs: update CLAUDE.md for v9b release
All checks were successful
Deploy Development / deploy (push) Successful in 56s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
Updated documentation to reflect v9b (PostgreSQL) release:

**Version Update:**
- v9a → v9b (PostgreSQL Migration complete)
- Tech Stack: SQLite → PostgreSQL 16 (Alpine)
- 60+ protected endpoints (was 44)

**New Features Documented:**
-  PostgreSQL migration (auto-migrate from SQLite)
-  Export: CSV, JSON, ZIP (with photos)
-  Admin: Edit prompts, set email/PIN
-  All API endpoints aligned (11 fixes)

**Environment Variables:**
- Added DB_* variables (PostgreSQL connection)
- Added ANTHROPIC_API_KEY (alternative to OpenRouter)

**Important Hints:**
- Updated: PostgreSQL migrations instead of SQLite safe_alters
- Added: RealDictCursor usage for dict-like row access
- Added: PostgreSQL boolean syntax (true/false not 1/0)

**New Section: v9b Migration – Lessons Learned**
- Docker build optimization (removed apt-get)
- Empty date string handling
- Boolean field conversion
- API endpoint consistency audit

**Roadmap Adjustment:**
- v9c: Tier System (was in v9b)
- v9d: OAuth2 Connectors (was in v9c)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 21:39:14 +01:00
1db780858b fix: align all API endpoints between frontend and backend
Fixed 11 critical endpoint mismatches found during codebase audit.

**Renamed Endpoints (consistency):**
- /api/ai/analyze/{slug} → /api/insights/run/{slug}
- /api/ai/analyze-pipeline → /api/insights/pipeline
- /api/auth/password-reset-request → /api/auth/forgot-password
- /api/auth/password-reset-confirm → /api/auth/reset-password
- /api/admin/test-email → /api/admin/email/test

**Added Missing Endpoints:**
- POST /api/auth/pin (change PIN/password for current user)
- PUT /api/admin/profiles/{id}/permissions (set permissions)
- PUT /api/admin/profiles/{id}/email (set email)
- PUT /api/admin/profiles/{id}/pin (admin set PIN)
- GET /api/admin/email/status (check SMTP config)
- PUT /api/prompts/{id} (edit prompt templates, admin only)
- GET /api/export/json (export all data as JSON)
- GET /api/export/zip (export data + photos as ZIP)

**Updated:**
- Added imports: json, zipfile, Response
- Fixed admin email test endpoint to accept dict body

All frontend API calls now have matching backend implementations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 17:07:41 +01:00
3d58a2db8e fix: add missing /api/insights endpoints
All checks were successful
Deploy Development / deploy (push) Successful in 56s
Build Test / lint-backend (push) Successful in 1s
Build Test / build-frontend (push) Successful in 13s
- Add GET /api/insights (returns all insights for profile)
- Add DELETE /api/insights/{id} (delete by ID, not scope)
- Frontend Analysis.jsx needs these endpoints to load/delete insights

Fixes 404 error preventing prompts from displaying.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 15:26:57 +01:00
36f334aba7 fix: PostgreSQL boolean syntax in prompts queries
All checks were successful
Deploy Development / deploy (push) Successful in 56s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
- Change WHERE active=1 to WHERE active=true (PostgreSQL uses boolean)
- Change endpoint from /api/ai/prompts to /api/prompts (simpler path)
- Fixed 5 occurrences across prompt-related queries

This fixes the issue where no prompts were returned, causing empty
prompt list in Admin and no AI analysis options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 13:55:14 +01:00
8390c7f510 feat: add missing API endpoints
All checks were successful
Deploy Development / deploy (push) Successful in 53s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
- Add GET /api/insights/latest (returns latest 10 insights)
- Add GET /api/auth/status (health check endpoint)

These endpoints were called by frontend but returned 404,
causing uncaught promise errors that blocked page loading.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:54:25 +01:00
79a951ce92 fix: use column names for COUNT queries with RealDictCursor
All checks were successful
Deploy Development / deploy (push) Successful in 58s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 12s
RealDictCursor returns dicts, not tuples. Cannot use [0] for index access.
Changed all COUNT(*) to COUNT(*) as count and access via ['count'].

Fixes: KeyError: 0 on cur.fetchone()[0]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:47:01 +01:00
9fbedb6c4b fix: use RealDictCursor for PostgreSQL row access
All checks were successful
Deploy Development / deploy (push) Successful in 54s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 12s
All conn.cursor() calls replaced with get_cursor(conn) to enable
dict-like row access (prof['pin_hash'] instead of prof[column_index]).

This fixes KeyError when accessing PostgreSQL query results.

Fixes: 'tuple' object has no attribute '__getitem__' with string keys

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:42:46 +01:00
124df01983 fix: convert empty date strings to NULL in migration
All checks were successful
Deploy Development / deploy (push) Successful in 54s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
PostgreSQL DATE type doesn't accept empty strings ('').
Convert empty/whitespace date values to NULL during migration.

Fixes: invalid input syntax for type date: ""

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:32:34 +01:00
7758bbf12e fix: add missing meas_id column to photos table
All checks were successful
Deploy Development / deploy (push) Successful in 55s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 12s
SQLite schema (v9a) has meas_id in photos table, but PostgreSQL
schema (v9b) was missing it. This caused migration to fail.

Added meas_id as nullable UUID column for backward compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:23:13 +01:00
d15ec056b4 fix: actually call migration function (was only importing)
All checks were successful
Deploy Development / deploy (push) Successful in 1m0s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
Bug: db_init.py was importing migrate_to_postgres but not calling main().
Result: Migration appeared successful but no data was migrated (0 users).

Fix: Import and call migrate_to_postgres.main()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:19:51 +01:00
39a7b1be78 feat: add PostgreSQL to production setup (v9b)
All checks were successful
Deploy Development / deploy (push) Successful in 57s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s
Prepares production for SQLite → PostgreSQL migration:
- Add postgres service (mitai-db, port 5432)
- Add DB environment variables to backend
- Backend depends on postgres health check
- Uses startup.sh for automatic migration

Migration strategy:
1. SQLite data in /app/data/bodytrack.db is preserved (volume mounted)
2. On first start with empty PostgreSQL: automatic migration
3. Migration is safe: checks if profiles table is empty before migrating
4. After migration: all new data goes to PostgreSQL

IMPORTANT: Set DB_PASSWORD in .env before deploying!

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:14:25 +01:00
d2c578de83 fix: add missing /app/data volume for SQLite migration
All checks were successful
Deploy Development / deploy (push) Successful in 1m3s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
The data volume was missing in dev environment, preventing automatic
SQLite → PostgreSQL migration. The SQLite database (bodytrack.db) was
not accessible to the container, so migration was skipped.

This fixes the "No SQLite database found" message when data exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:11:37 +01:00
6f0f1ae9b4 fix: send 'password' instead of 'pin' in login request
All checks were successful
Deploy Development / deploy (push) Successful in 53s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
Frontend was sending {email, pin} but backend expects {email, password}.
This caused 422 Unprocessable Entity errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:04:36 +01:00
ad433a470f fix: PostgreSQL trigger syntax (remove IF NOT EXISTS)
All checks were successful
Deploy Development / deploy (push) Successful in 54s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
PostgreSQL does not support IF NOT EXISTS for CREATE TRIGGER.
Use DROP TRIGGER IF EXISTS before CREATE TRIGGER instead.

Fixes: Backend crash loop due to schema.sql syntax error on line 231

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 11:59:09 +01:00
627eb8e265 fix: replace psql with Python for DB checks (no apt-get needed!)
Some checks failed
Deploy Development / deploy (push) Failing after 3s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 31s
- Remove postgresql-client installation (causes 150s+ hangs due to network)
- Add db_init.py: Pure Python PostgreSQL checks using psycopg2-binary
- Simplify startup.sh: Call Python script instead of psql commands
- Build should now complete in <30s instead of hanging

This fixes the deployment timeout issue by avoiding APT network problems entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 10:01:19 +01:00
67b00b941e fix: force IPv4 and add aggressive timeouts for APT
Some checks failed
Deploy Development / deploy (push) Has been cancelled
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 22s
- Force IPv4 (IPv6 shows 33% packet loss)
- Increase retries to 5
- Add 10s timeouts to fail fast and retry
- Previous fix improved from 1630s to 78s but still hangs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 09:52:44 +01:00
ec3c279e11 fix: use German APT mirror for better connectivity
Some checks failed
Build Test / lint-backend (push) Waiting to run
Build Test / build-frontend (push) Waiting to run
Deploy Development / deploy (push) Has been cancelled
- Switch from deb.debian.org to ftp.de.debian.org (33% packet loss observed)
- Add APT retry logic (3 attempts) for flaky connections
- Fixes deployment timeout on backend build (postgresql-client install)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 09:48:23 +01:00
56edd16368 small update
Some checks failed
Deploy Development / deploy (push) Has been cancelled
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 29s
2026-03-18 09:07:08 +01:00
0a871fea22 9b
Some checks failed
Deploy Development / deploy (push) Failing after 1s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 1m6s
2026-03-18 08:27:33 +01:00
c4cead9e27 docs: add comprehensive design system to CLAUDE.md
Some checks failed
Deploy Development / deploy (push) Failing after 11m50s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 30s
Added detailed documentation for:
- Color system (CSS variables)
- CSS class conventions
- Spacing & sizing standards
- Component patterns (loading, error, empty states)
- Jinkendo logo system
- Available custom commands

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 06:13:58 +01:00
c36085daa4 md code aktualisiert V9
All checks were successful
Deploy Development / deploy (push) Successful in 56s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
2026-03-17 14:08:44 +01:00
4a6dc37854 ci: fix workflows - prod deploys to bodytrack/, dev to bodytrack-dev/
All checks were successful
Deploy Development / deploy (push) Successful in 1m9s
Deploy Production / deploy (push) Successful in 51s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
2026-03-17 13:11:53 +01:00
eadc0ea39c feat: add dev environment docker-compose
All checks were successful
Deploy Development / deploy (push) Successful in 56s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s
2026-03-17 13:10:24 +01:00
1d169b1228 ci: fix test workflow - use local Node.js
All checks were successful
Deploy Development / deploy (push) Successful in 56s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 1m15s
2026-03-17 12:58:56 +01:00
b409a22322 ci: add prod and dev deployment workflows
Some checks failed
Deploy Development / deploy (push) Successful in 55s
Build Test / build-frontend (push) Failing after 2s
Build Test / lint-backend (push) Failing after 1s
2026-03-17 12:53:32 +01:00
5091dfd1ce fix: add auth token to all API calls (prompts, insights, pipeline)
Some checks failed
Deploy to Raspberry Pi / deploy (push) Failing after 12s
Build Test / build-frontend (push) Failing after 2s
Build Test / lint-backend (push) Failing after 1s
2026-03-16 16:52:36 +01:00
89b6c0b072 feat: initial commit – Mitai Jinkendo v9a
Some checks are pending
Deploy to Raspberry Pi / deploy (push) Waiting to run
Build Test / build-frontend (push) Waiting to run
Build Test / lint-backend (push) Waiting to run
2026-03-16 13:35:11 +01:00