API: Add GET /api/user/comparisons for profile page #2

Closed
opened 2026-04-26 08:15:01 +00:00 by TopherMayor · 0 comments
Owner

Summary

The Profile page shows hardcoded mock data. We need an endpoint to fetch the authenticated user's comparisons.

Implementation

  1. Create src/app/api/user/comparisons/route.ts

    • GET /api/user/comparisons?page=1&limit=20
    • Requires authentication (return 401 if not logged in)
    • Query comparisons where userId = current user
    • Order by createdAt DESC
    • Include item names from comparisonItems join
    • Return same shape as public feed but include private comparisons
  2. Create src/app/api/user/stats/route.ts

    • GET /api/user/stats
    • Return: { totalComparisons, totalViews, recentComparisons[] }
    • Used for profile stat cards

Response Shape

{
  "comparisons": [{
    "id": "...",
    "title": "...",
    "slug": "...",
    "tags": ["Tech"],
    "items": ["React", "Vue"],
    "status": "completed",
    "isPublic": true,
    "viewCount": 1247,
    "overallScore": 8.5,
    "createdAt": "2024-01-15T..."
  }],
  "total": 12,
  "page": 1
}

Files

  • Create: src/app/api/user/comparisons/route.ts
  • Create: src/app/api/user/stats/route.ts
  • Reference: src/app/actions/comparison.ts (getUserComparisons at line 94-100)

Acceptance Criteria

  • GET /api/user/comparisons returns authenticated user's comparisons
  • Returns 401 for unauthenticated requests
  • Includes both public and private comparisons
  • Paginated with total count
## Summary The Profile page shows hardcoded mock data. We need an endpoint to fetch the authenticated user's comparisons. ## Implementation 1. **Create** `src/app/api/user/comparisons/route.ts` - `GET /api/user/comparisons?page=1&limit=20` - Requires authentication (return 401 if not logged in) - Query comparisons where `userId = current user` - Order by `createdAt DESC` - Include item names from `comparisonItems` join - Return same shape as public feed but include private comparisons 2. **Create** `src/app/api/user/stats/route.ts` - `GET /api/user/stats` - Return: `{ totalComparisons, totalViews, recentComparisons[] }` - Used for profile stat cards ## Response Shape ```json { "comparisons": [{ "id": "...", "title": "...", "slug": "...", "tags": ["Tech"], "items": ["React", "Vue"], "status": "completed", "isPublic": true, "viewCount": 1247, "overallScore": 8.5, "createdAt": "2024-01-15T..." }], "total": 12, "page": 1 } ``` ## Files - Create: `src/app/api/user/comparisons/route.ts` - Create: `src/app/api/user/stats/route.ts` - Reference: `src/app/actions/comparison.ts` (`getUserComparisons` at line 94-100) ## Acceptance Criteria - [ ] GET /api/user/comparisons returns authenticated user's comparisons - [ ] Returns 401 for unauthenticated requests - [ ] Includes both public and private comparisons - [ ] Paginated with total count
TopherMayor added this to the v0.2 - Feed & Profile milestone 2026-04-26 08:15:01 +00:00
TopherMayor added the featurebackend labels 2026-04-26 08:15:01 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TopherMayor/comparaison#2