Implement POST /api/cycle/period endpoint (P1.2)
Add period logging endpoint that allows users to record their period start date. This is a critical path item that unblocks GET /api/cycle/current and GET /api/today. Features: - Protected with withAuth middleware - Validates startDate is present, valid format (YYYY-MM-DD), and not in future - Updates user.lastPeriodDate in PocketBase - Creates PeriodLog record for historical tracking - Returns updated cycle information (cycleDay, phase) Tests: 8 tests covering authentication, validation, database operations, and error handling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
|
||||
|-------|--------|-------|
|
||||
| GET /api/user | **COMPLETE** | Returns user profile with `withAuth()` |
|
||||
| PATCH /api/user | 501 | Returns Not Implemented |
|
||||
| POST /api/cycle/period | 501 | Returns Not Implemented |
|
||||
| POST /api/cycle/period | **COMPLETE** | Logs period start, updates user, creates PeriodLog (8 tests) |
|
||||
| GET /api/cycle/current | 501 | Returns Not Implemented |
|
||||
| GET /api/today | 501 | Returns Not Implemented |
|
||||
| POST /api/overrides | 501 | Returns Not Implemented |
|
||||
@@ -71,6 +71,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
|
||||
| `src/lib/auth-middleware.test.ts` | **EXISTS** - 6 tests (withAuth wrapper, error handling) |
|
||||
| `src/middleware.test.ts` | **EXISTS** - 12 tests (page protection, public routes, static assets) |
|
||||
| `src/app/api/user/route.test.ts` | **EXISTS** - 4 tests (GET profile, auth, sensitive field exclusion) |
|
||||
| `src/app/api/cycle/period/route.test.ts` | **EXISTS** - 8 tests (POST period, auth, validation, date checks) |
|
||||
| `src/lib/nutrition.test.ts` | **MISSING** |
|
||||
| `src/lib/email.test.ts` | **MISSING** |
|
||||
| `src/lib/ics.test.ts` | **MISSING** |
|
||||
@@ -154,12 +155,12 @@ Minimum viable product - app can be used for daily decisions.
|
||||
- **Why:** Users need to configure their cycle and preferences
|
||||
- **Depends On:** P0.1, P0.2
|
||||
|
||||
### P1.2: POST /api/cycle/period Implementation
|
||||
- [ ] Log period start date, update user record, create PeriodLog
|
||||
### P1.2: POST /api/cycle/period Implementation ✅ COMPLETE
|
||||
- [x] Log period start date, update user record, create PeriodLog
|
||||
- **Files:**
|
||||
- `src/app/api/cycle/period/route.ts` - Implement POST handler
|
||||
- `src/app/api/cycle/period/route.ts` - Implemented POST handler with validation
|
||||
- **Tests:**
|
||||
- `src/app/api/cycle/period/route.test.ts` - Test date validation, user update, log creation
|
||||
- `src/app/api/cycle/period/route.test.ts` - 8 tests covering auth, date validation, user update, PeriodLog creation
|
||||
- **Why:** Cycle tracking is the foundation of all recommendations
|
||||
- **Depends On:** P0.1, P0.2
|
||||
|
||||
@@ -481,6 +482,7 @@ P2.14 Mini calendar
|
||||
|
||||
### API Routes
|
||||
- [x] **GET /api/user** - Returns authenticated user profile, 4 tests (P0.4)
|
||||
- [x] **POST /api/cycle/period** - Logs period start date, updates user, creates PeriodLog, 8 tests (P1.2)
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user