Compare commits
21 Commits
aac0e2f5b1
...
fix/e2e-bu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eab1618d04 | ||
|
|
273b600e98 | ||
|
|
024f3cb1f7 | ||
|
|
cd51f2a0c8 | ||
|
|
4d5e1502e9 | ||
|
|
56b6f67d00 | ||
|
|
370fd2d8e6 | ||
|
|
089de443a0 | ||
|
|
78e1c74fa3 | ||
|
|
d9ed1586cc | ||
|
|
5187d75d53 | ||
|
|
8d2239aebd | ||
|
|
0b523b7274 | ||
|
|
db30a7e178 | ||
|
|
50fd4cda6a | ||
|
|
565085aba1 | ||
|
|
c9e6e156ac | ||
|
|
494dcb91fa | ||
|
|
3c5df6a74c | ||
|
|
7888d7995c | ||
|
|
3689b1707a |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -40,3 +40,8 @@ yarn-error.log*
|
|||||||
# typescript
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
|
# Worktrees (tracked via branches)
|
||||||
|
comparaison-backend/
|
||||||
|
comparaison-llm/
|
||||||
|
comparaison-ui/
|
||||||
|
|||||||
38
README.md
38
README.md
@@ -85,6 +85,44 @@ npm run dev
|
|||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
**Production URL:** [https://comparaison.local.tophermayor.com](https://comparaison.local.tophermayor.com)
|
||||||
|
|
||||||
|
| Detail | Value |
|
||||||
|
|---|---|
|
||||||
|
| Host | `ubuntu` (`192.168.50.61`) |
|
||||||
|
| Compose file | `/srv/compose/comparaison/docker-compose.yml` |
|
||||||
|
| Reverse proxy | Traefik (shared instance on `proxy-net`) |
|
||||||
|
| Database | Shared PostgreSQL (`postgres-shared` container on `proxy-net`) |
|
||||||
|
| Routing | Docker labels on the app container (Traefik router/rules) |
|
||||||
|
|
||||||
|
### Production Setup
|
||||||
|
|
||||||
|
1. **Traefik Ingress** — A shared Traefik instance handles TLS termination and routes traffic to the app container via Docker labels. The app joins the `proxy-net` network so Traefik can reach it.
|
||||||
|
|
||||||
|
2. **Shared PostgreSQL** — A standalone `postgres-shared` container provides the database. The comparaison app connects to it over `proxy-net`. No separate DB container is defined in the app's compose file.
|
||||||
|
|
||||||
|
3. **Environment** — The following are configured in the production environment:
|
||||||
|
- `DATABASE_URL` — Points to the shared Postgres instance
|
||||||
|
- `BETTER_AUTH_SECRET` — Random secret for session signing
|
||||||
|
- `OPENAI_API_KEY`, `TAVILY_API_KEY`, `PERPLEXITY_API_KEY` — LLM provider keys
|
||||||
|
- `NEXT_PUBLIC_APP_URL` — `https://comparaison.local.tophermayor.com`
|
||||||
|
|
||||||
|
### Deploying Updates
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# On ubuntu (192.168.50.61)
|
||||||
|
cd /srv/compose/comparaison
|
||||||
|
docker compose pull && docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Recent Fixes
|
||||||
|
|
||||||
|
- Added `userId` to comparison inserts so saved comparisons are properly associated with authenticated users
|
||||||
|
- Fixed OpenAI provider `getClient()` to correctly initialize the OpenAI client
|
||||||
|
- Added `BETTER_AUTH_SECRET` to production environment for proper session management
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,30 +1,24 @@
|
|||||||
version: "3.8"
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
container_name: comparaison
|
||||||
- "3000:3000"
|
|
||||||
environment:
|
|
||||||
- DATABASE_URL=postgresql://postgres:postgres@db:5432/comparaison
|
|
||||||
depends_on:
|
|
||||||
db:
|
|
||||||
condition: service_healthy
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
db:
|
|
||||||
image: postgres:16-alpine
|
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: postgres
|
- DATABASE_URL=postgresql://bear:changeme@postgres-shared:5432/comparaison
|
||||||
POSTGRES_PASSWORD: postgres
|
- BETTER_AUTH_SECRET=Y6oPTrn3adCnf+Bx60/4g3KjuBfLGVJJB9NFKR5bbVk=
|
||||||
POSTGRES_DB: comparaison
|
- BETTER_AUTH_URL=https://comparaison.local.tophermayor.com
|
||||||
ports:
|
- NODE_ENV=production
|
||||||
- "5432:5432"
|
networks:
|
||||||
volumes:
|
- proxy-net
|
||||||
- pgdata:/var/lib/postgresql/data
|
labels:
|
||||||
healthcheck:
|
- "traefik.enable=true"
|
||||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
- "traefik.http.routers.comparaison.rule=Host(`comparaison.local.tophermayor.com`)"
|
||||||
interval: 5s
|
- "traefik.http.routers.comparaison.entrypoints=websecure"
|
||||||
timeout: 5s
|
- "traefik.http.routers.comparaison.tls=true"
|
||||||
retries: 5
|
- "traefik.http.routers.comparaison.tls.certresolver=cloudflare"
|
||||||
restart: unless-stopped
|
- "traefik.http.routers.comparaison.middlewares=local-only@file"
|
||||||
volumes:
|
- "traefik.http.services.comparaison.loadbalancer.server.port=3000"
|
||||||
pgdata:
|
|
||||||
|
networks:
|
||||||
|
proxy-net:
|
||||||
|
external: true
|
||||||
|
|||||||
458
docs/plans/2026-04-26-feed-profile-auth.md
Normal file
458
docs/plans/2026-04-26-feed-profile-auth.md
Normal file
@@ -0,0 +1,458 @@
|
|||||||
|
# ComparAIson v0.2–v0.4 Implementation Plan
|
||||||
|
|
||||||
|
> **For Hermes:** Use subagent-driven-development skill to implement this plan task-by-task.
|
||||||
|
|
||||||
|
**Goal:** Replace all mock data with real API-backed pages, wire auth into the comparison flow, and add search + management features.
|
||||||
|
|
||||||
|
**Architecture:** Next.js App Router API routes backed by existing Drizzle ORM schema. Server actions for simple reads, REST endpoints for complex queries. Better Auth sessions for user identity.
|
||||||
|
|
||||||
|
**Tech Stack:** Next.js 15, Drizzle ORM, PostgreSQL, Better Auth, shadcn/ui, Recharts
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Dependency Graph
|
||||||
|
|
||||||
|
```
|
||||||
|
v0.2 Feed & Profile (issues #1-#4)
|
||||||
|
#1 API: Public feed endpoint ──────┐
|
||||||
|
#2 API: User comparisons endpoint ─┤
|
||||||
|
├──> #3 Wire Explore page
|
||||||
|
├──> #4 Wire Profile page
|
||||||
|
|
||||||
|
v0.3 Auth Integration (issue #5)
|
||||||
|
#5 Associate comparisons with users
|
||||||
|
|
||||||
|
v0.4 Search & Polish (issues #6-#8)
|
||||||
|
#6 Functional search ──> depends on #3
|
||||||
|
#7 Delete/toggle visibility ──> depends on #5
|
||||||
|
#8 Loading/error states ──> can start anytime
|
||||||
|
```
|
||||||
|
|
||||||
|
## Recommended Execution Order
|
||||||
|
|
||||||
|
1. **#1** — API: Public feed endpoint (no dependencies)
|
||||||
|
2. **#2** — API: User comparisons endpoint (no dependencies)
|
||||||
|
3. **#3** — Wire Explore page (depends on #1)
|
||||||
|
4. **#4** — Wire Profile page (depends on #2)
|
||||||
|
5. **#5** — Associate comparisons with users (foundational for v0.3)
|
||||||
|
6. **#6** — Functional search (depends on #3)
|
||||||
|
7. **#7** — Delete/toggle visibility (depends on #5)
|
||||||
|
8. **#8** — Loading/error states (independent, can parallelize)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 1: v0.2 — Feed & Profile (Milestone #5)
|
||||||
|
|
||||||
|
### Task 1.1: Create GET /api/comparisons route (#1)
|
||||||
|
|
||||||
|
**Objective:** Paginated public feed API endpoint.
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Create: `src/app/api/comparisons/route.ts`
|
||||||
|
|
||||||
|
**Step 1: Create the route file**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/app/api/comparisons/route.ts
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
||||||
|
import { eq, and, ilike, desc, sql } from "drizzle-orm";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Math.max(1, Number(searchParams.get("page")) || 1);
|
||||||
|
const limit = Math.min(50, Math.max(1, Number(searchParams.get("limit")) || 20));
|
||||||
|
const search = searchParams.get("search")?.trim() || "";
|
||||||
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
|
const conditions = [
|
||||||
|
eq(comparisons.isPublic, true),
|
||||||
|
eq(comparisons.status, "completed"),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
conditions.push(ilike(comparisons.title, `%${search}%`));
|
||||||
|
}
|
||||||
|
|
||||||
|
const where = and(...conditions);
|
||||||
|
|
||||||
|
const [rows, countResult] = await Promise.all([
|
||||||
|
db
|
||||||
|
.select()
|
||||||
|
.from(comparisons)
|
||||||
|
.where(where)
|
||||||
|
.orderBy(desc(comparisons.createdAt))
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset),
|
||||||
|
db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(comparisons)
|
||||||
|
.where(where),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const total = countResult[0]?.count ?? 0;
|
||||||
|
|
||||||
|
// Fetch item names for each comparison
|
||||||
|
const comparisonIds = rows.map((r) => r.id);
|
||||||
|
const items = comparisonIds.length
|
||||||
|
? await db
|
||||||
|
.select({
|
||||||
|
comparisonId: comparisonItems.comparisonId,
|
||||||
|
name: comparisonItems.name,
|
||||||
|
})
|
||||||
|
.from(comparisonItems)
|
||||||
|
.where(sql`${comparisonItems.comparisonId} IN ${comparisonIds}`)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const itemsByComparison = items.reduce<Record<string, string[]>>(
|
||||||
|
(acc, item) => {
|
||||||
|
if (!acc[item.comparisonId]) acc[item.comparisonId] = [];
|
||||||
|
acc[item.comparisonId].push(item.name);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
comparisons: rows.map((row) => ({
|
||||||
|
id: row.id,
|
||||||
|
title: row.title,
|
||||||
|
summary: row.summary?.slice(0, 200) || "",
|
||||||
|
slug: row.slug,
|
||||||
|
tags: row.tags || [],
|
||||||
|
items: itemsByComparison[row.id] || [],
|
||||||
|
viewCount: row.viewCount,
|
||||||
|
createdAt: row.createdAt.toISOString(),
|
||||||
|
})),
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 2: Create GET /api/comparisons/[slug]/route.ts**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/app/api/comparisons/[slug]/route.ts
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
||||||
|
import { eq, sql } from "drizzle-orm";
|
||||||
|
import { getComparison } from "@/app/actions/comparison";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: Promise<{ slug: string }> }
|
||||||
|
) {
|
||||||
|
const { slug } = await params;
|
||||||
|
|
||||||
|
// Increment view count
|
||||||
|
await db
|
||||||
|
.update(comparisons)
|
||||||
|
.set({ viewCount: sql`${comparisons.viewCount} + 1` })
|
||||||
|
.where(eq(comparisons.slug, slug));
|
||||||
|
|
||||||
|
const data = await getComparison(slug);
|
||||||
|
if (!data) {
|
||||||
|
return Response.json({ error: "Not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json(data);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 3: Verify**
|
||||||
|
```bash
|
||||||
|
npm run build # check for type errors
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 1.2: Create GET /api/user/comparisons and /api/user/stats (#2)
|
||||||
|
|
||||||
|
**Objective:** User-specific comparison listing and stats.
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Create: `src/app/api/user/comparisons/route.ts`
|
||||||
|
- Create: `src/app/api/user/stats/route.ts`
|
||||||
|
|
||||||
|
**Step 1: User comparisons endpoint**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/app/api/user/comparisons/route.ts
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
||||||
|
import { eq, desc, sql } from "drizzle-orm";
|
||||||
|
import { auth } from "@/lib/auth";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const session = await auth.api.getSession({ headers: await headers() });
|
||||||
|
if (!session?.user) {
|
||||||
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Math.max(1, Number(searchParams.get("page")) || 1);
|
||||||
|
const limit = Math.min(50, Math.max(1, Number(searchParams.get("limit")) || 20));
|
||||||
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
|
const userId = session.user.id;
|
||||||
|
|
||||||
|
const [rows, countResult] = await Promise.all([
|
||||||
|
db
|
||||||
|
.select()
|
||||||
|
.from(comparisons)
|
||||||
|
.where(eq(comparisons.userId, userId))
|
||||||
|
.orderBy(desc(comparisons.createdAt))
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset),
|
||||||
|
db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(comparisons)
|
||||||
|
.where(eq(comparisons.userId, userId)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const total = countResult[0]?.count ?? 0;
|
||||||
|
|
||||||
|
const comparisonIds = rows.map((r) => r.id);
|
||||||
|
const items = comparisonIds.length
|
||||||
|
? await db
|
||||||
|
.select({
|
||||||
|
comparisonId: comparisonItems.comparisonId,
|
||||||
|
name: comparisonItems.name,
|
||||||
|
})
|
||||||
|
.from(comparisonItems)
|
||||||
|
.where(sql`${comparisonItems.comparisonId} IN ${comparisonIds}`)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const itemsByComparison = items.reduce<Record<string, string[]>>(
|
||||||
|
(acc, item) => {
|
||||||
|
if (!acc[item.comparisonId]) acc[item.comparisonId] = [];
|
||||||
|
acc[item.comparisonId].push(item.name);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
comparisons: rows.map((row) => ({
|
||||||
|
id: row.id,
|
||||||
|
title: row.title,
|
||||||
|
slug: row.slug,
|
||||||
|
tags: row.tags || [],
|
||||||
|
items: itemsByComparison[row.id] || [],
|
||||||
|
status: row.status,
|
||||||
|
isPublic: row.isPublic,
|
||||||
|
viewCount: row.viewCount,
|
||||||
|
createdAt: row.createdAt.toISOString(),
|
||||||
|
})),
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 2: User stats endpoint**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/app/api/user/stats/route.ts
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons } from "@/lib/db/schema";
|
||||||
|
import { eq, sql } from "drizzle-orm";
|
||||||
|
import { auth } from "@/lib/auth";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const session = await auth.api.getSession({ headers: await headers() });
|
||||||
|
if (!session?.user) {
|
||||||
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const userId = session.user.id;
|
||||||
|
|
||||||
|
const stats = await db
|
||||||
|
.select({
|
||||||
|
totalComparisons: sql<number>`count(*)`,
|
||||||
|
totalViews: sql<number>`coalesce(sum(${comparisons.viewCount}), 0)`,
|
||||||
|
})
|
||||||
|
.from(comparisons)
|
||||||
|
.where(eq(comparisons.userId, userId));
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
totalComparisons: stats[0]?.totalComparisons ?? 0,
|
||||||
|
totalViews: stats[0]?.totalViews ?? 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 3: Verify**
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 1.3: Wire Explore page (#3)
|
||||||
|
|
||||||
|
**Objective:** Replace mock data with real API calls.
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/app/(main)/explore/page.tsx`
|
||||||
|
|
||||||
|
**Step 1: Replace mock data with fetch logic**
|
||||||
|
|
||||||
|
Replace the entire `allComparisons` array and `categories` with:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from "react"
|
||||||
|
// ... existing imports ...
|
||||||
|
|
||||||
|
interface ExploreComparison {
|
||||||
|
id: string
|
||||||
|
title: string
|
||||||
|
summary: string
|
||||||
|
slug: string
|
||||||
|
tags: string[]
|
||||||
|
items: string[]
|
||||||
|
viewCount: number
|
||||||
|
createdAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ExplorePage() {
|
||||||
|
const [searchQuery, setSearchQuery] = useState("")
|
||||||
|
const [comparisons, setComparisons] = useState<ExploreComparison[]>([])
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const limit = 20
|
||||||
|
|
||||||
|
const fetchComparisons = useCallback(async (search: string, pageNum: number) => {
|
||||||
|
setLoading(true)
|
||||||
|
setError(null)
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
page: String(pageNum),
|
||||||
|
limit: String(limit),
|
||||||
|
})
|
||||||
|
if (search) params.set("search", search)
|
||||||
|
const res = await fetch(`/api/comparisons?${params}`)
|
||||||
|
if (!res.ok) throw new Error("Failed to fetch")
|
||||||
|
const data = await res.json()
|
||||||
|
if (pageNum === 1) {
|
||||||
|
setComparisons(data.comparisons)
|
||||||
|
} else {
|
||||||
|
setComparisons((prev) => [...prev, ...data.comparisons])
|
||||||
|
}
|
||||||
|
setTotal(data.total)
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Failed to load comparisons")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// Debounced search
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setPage(1)
|
||||||
|
fetchComparisons(searchQuery, 1)
|
||||||
|
}, 300)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}, [searchQuery, fetchComparisons])
|
||||||
|
|
||||||
|
// Initial load
|
||||||
|
useEffect(() => {
|
||||||
|
fetchComparisons("", 1)
|
||||||
|
}, [fetchComparisons])
|
||||||
|
|
||||||
|
// Extract unique tags from loaded comparisons
|
||||||
|
const categories = ["All", ...new Set(comparisons.flatMap((c) => c.tags))]
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState("All")
|
||||||
|
|
||||||
|
const filtered = selectedCategory === "All"
|
||||||
|
? comparisons
|
||||||
|
: comparisons.filter((c) => c.tags.includes(selectedCategory))
|
||||||
|
|
||||||
|
const hasMore = comparisons.length < total
|
||||||
|
|
||||||
|
// ... render (replace allComparisons references with `filtered`)
|
||||||
|
// Change Link href from `/compare/${comparison.id}` to `/compare/${comparison.slug}`
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 2: Update "Load More" button**
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="gap-2"
|
||||||
|
onClick={() => {
|
||||||
|
const nextPage = page + 1
|
||||||
|
setPage(nextPage)
|
||||||
|
fetchComparisons(searchQuery, nextPage)
|
||||||
|
}}
|
||||||
|
disabled={loading || !hasMore}
|
||||||
|
>
|
||||||
|
{loading ? "Loading..." : "Load More"}
|
||||||
|
</Button>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 1.4: Wire Profile page (#4)
|
||||||
|
|
||||||
|
**Objective:** Replace mock data with real user data.
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/app/(main)/profile/page.tsx`
|
||||||
|
|
||||||
|
Similar pattern to Explore — replace mock arrays with `useEffect` + `fetch` to `/api/user/comparisons` and `/api/user/stats`. Show sign-in CTA if no session.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 2: v0.3 — Auth Integration (Milestone #6)
|
||||||
|
|
||||||
|
### Task 2.1: Associate comparisons with users (#5)
|
||||||
|
|
||||||
|
**Objective:** Set userId on comparison creation.
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/app/api/compare/route.ts`
|
||||||
|
- Modify: `src/app/actions/comparison.ts`
|
||||||
|
|
||||||
|
Read auth session from headers, extract userId, pass to insert. Add auth check to compare page.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 3: v0.4 — Search & Polish (Milestone #7)
|
||||||
|
|
||||||
|
### Task 3.1: Functional search (#6)
|
||||||
|
|
||||||
|
Navigate header search to `/explore?search=...`. Read URL params in Explore page.
|
||||||
|
|
||||||
|
### Task 3.2: Delete/toggle visibility (#7)
|
||||||
|
|
||||||
|
Add `DELETE` and `PATCH` routes. Add dropdown menus to profile comparison cards.
|
||||||
|
|
||||||
|
### Task 3.3: Loading/error states (#8)
|
||||||
|
|
||||||
|
Add error rendering in compare page, error boundary, toast notifications.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Gitea Issues Summary
|
||||||
|
|
||||||
|
| # | Title | Labels | Milestone |
|
||||||
|
|---|-------|--------|-----------|
|
||||||
|
| 1 | API: Public feed endpoint | feature, backend | v0.2 |
|
||||||
|
| 2 | API: User comparisons endpoint | feature, backend | v0.2 |
|
||||||
|
| 3 | Wire Explore page | feature, frontend | v0.2 |
|
||||||
|
| 4 | Wire Profile page | feature, frontend | v0.2 |
|
||||||
|
| 5 | Associate comparisons with users | bug, backend | v0.3 |
|
||||||
|
| 6 | Functional search | feature, frontend | v0.4 |
|
||||||
|
| 7 | Delete/toggle visibility | feature, frontend, backend | v0.4 |
|
||||||
|
| 8 | Loading/error states | improvement, frontend | v0.4 |
|
||||||
59
drizzle/0000_gorgeous_puma.sql
Normal file
59
drizzle/0000_gorgeous_puma.sql
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
CREATE TYPE "public"."comparison_status" AS ENUM('researching', 'completed', 'failed');--> statement-breakpoint
|
||||||
|
CREATE TABLE "comparison_dimensions" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"comparison_id" text NOT NULL,
|
||||||
|
"name" text NOT NULL,
|
||||||
|
"description" text,
|
||||||
|
"weight" integer DEFAULT 1 NOT NULL,
|
||||||
|
"order" integer DEFAULT 0 NOT NULL
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "comparison_items" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"comparison_id" text NOT NULL,
|
||||||
|
"name" text NOT NULL,
|
||||||
|
"description" text,
|
||||||
|
"image_url" text,
|
||||||
|
"research_data" jsonb,
|
||||||
|
"scores" jsonb,
|
||||||
|
"pros" text[],
|
||||||
|
"cons" text[],
|
||||||
|
"order" integer DEFAULT 0 NOT NULL
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "comparisons" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"user_id" text NOT NULL,
|
||||||
|
"title" text NOT NULL,
|
||||||
|
"query" text NOT NULL,
|
||||||
|
"slug" text NOT NULL,
|
||||||
|
"status" "comparison_status" DEFAULT 'researching' NOT NULL,
|
||||||
|
"summary" text,
|
||||||
|
"overall_data" jsonb,
|
||||||
|
"tags" text[],
|
||||||
|
"is_public" boolean DEFAULT true NOT NULL,
|
||||||
|
"view_count" integer DEFAULT 0 NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
CONSTRAINT "comparisons_slug_unique" UNIQUE("slug")
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "users" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"name" text,
|
||||||
|
"email" text NOT NULL,
|
||||||
|
"email_verified" timestamp with time zone,
|
||||||
|
"image" text,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
CONSTRAINT "users_email_unique" UNIQUE("email")
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "comparison_dimensions" ADD CONSTRAINT "comparison_dimensions_comparison_id_comparisons_id_fk" FOREIGN KEY ("comparison_id") REFERENCES "public"."comparisons"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "comparison_items" ADD CONSTRAINT "comparison_items_comparison_id_comparisons_id_fk" FOREIGN KEY ("comparison_id") REFERENCES "public"."comparisons"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "comparisons" ADD CONSTRAINT "comparisons_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||||
|
CREATE INDEX "comparison_dimensions_comparison_id_idx" ON "comparison_dimensions" USING btree ("comparison_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "comparison_items_comparison_id_idx" ON "comparison_items" USING btree ("comparison_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "comparisons_user_id_idx" ON "comparisons" USING btree ("user_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "comparisons_slug_idx" ON "comparisons" USING btree ("slug");--> statement-breakpoint
|
||||||
|
CREATE INDEX "comparisons_status_idx" ON "comparisons" USING btree ("status");
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
CREATE TABLE "comparison_dimensions" (
|
|
||||||
"id" text PRIMARY KEY NOT NULL,
|
|
||||||
"comparison_id" text NOT NULL,
|
|
||||||
"name" text NOT NULL,
|
|
||||||
"description" text,
|
|
||||||
"weight" integer DEFAULT 1,
|
|
||||||
"order" integer NOT NULL
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE TABLE "comparison_items" (
|
|
||||||
"id" text PRIMARY KEY NOT NULL,
|
|
||||||
"comparison_id" text NOT NULL,
|
|
||||||
"name" text NOT NULL,
|
|
||||||
"description" text,
|
|
||||||
"image_url" text,
|
|
||||||
"research_data" jsonb,
|
|
||||||
"scores" jsonb,
|
|
||||||
"pros" text[],
|
|
||||||
"cons" text[],
|
|
||||||
"order" integer NOT NULL
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE TABLE "comparisons" (
|
|
||||||
"id" text PRIMARY KEY NOT NULL,
|
|
||||||
"user_id" text,
|
|
||||||
"title" text NOT NULL,
|
|
||||||
"query" text,
|
|
||||||
"slug" varchar(255) NOT NULL,
|
|
||||||
"status" text DEFAULT 'researching' NOT NULL,
|
|
||||||
"summary" text,
|
|
||||||
"overall_data" jsonb,
|
|
||||||
"tags" text[],
|
|
||||||
"is_public" boolean DEFAULT false,
|
|
||||||
"view_count" integer DEFAULT 0,
|
|
||||||
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
||||||
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
||||||
CONSTRAINT "comparisons_slug_unique" UNIQUE("slug")
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
ALTER TABLE "comparison_dimensions" ADD CONSTRAINT "comparison_dimensions_comparison_id_comparisons_id_fk" FOREIGN KEY ("comparison_id") REFERENCES "public"."comparisons"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
||||||
ALTER TABLE "comparison_items" ADD CONSTRAINT "comparison_items_comparison_id_comparisons_id_fk" FOREIGN KEY ("comparison_id") REFERENCES "public"."comparisons"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
||||||
CREATE INDEX "comparisons_user_id_idx" ON "comparisons" USING btree ("user_id");
|
|
||||||
1
drizzle/0001_fix_email_verified.sql
Normal file
1
drizzle/0001_fix_email_verified.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "users" ALTER COLUMN "email_verified" SET DATA TYPE boolean USING ("email_verified" IS NOT NULL);
|
||||||
17
drizzle/0002_add_accounts_table.sql
Normal file
17
drizzle/0002_add_accounts_table.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE TABLE "accounts" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"user_id" text NOT NULL,
|
||||||
|
"account_id" text NOT NULL,
|
||||||
|
"provider_id" text NOT NULL,
|
||||||
|
"access_token" text,
|
||||||
|
"refresh_token" text,
|
||||||
|
"access_token_expires_at" timestamp,
|
||||||
|
"refresh_token_expires_at" timestamp,
|
||||||
|
"scope" text,
|
||||||
|
"id_token" text,
|
||||||
|
"password" text,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
|
CREATE INDEX "accounts_user_id_idx" ON "accounts" USING btree ("user_id");
|
||||||
8
drizzle/0003_add_verifications_table.sql
Normal file
8
drizzle/0003_add_verifications_table.sql
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS "verifications" (
|
||||||
|
"id" text PRIMARY KEY NOT NULL,
|
||||||
|
"identifier" text NOT NULL,
|
||||||
|
"value" text NOT NULL,
|
||||||
|
"expires_at" timestamp NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now(),
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now()
|
||||||
|
);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"id": "6cc67b11-8016-409b-9de9-8966593c97b0",
|
"id": "c719fbf4-6ed1-4b38-9a09-33a7e0799267",
|
||||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||||
"version": "7",
|
"version": "7",
|
||||||
"dialect": "postgresql",
|
"dialect": "postgresql",
|
||||||
@@ -36,17 +36,34 @@
|
|||||||
"name": "weight",
|
"name": "weight",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": true,
|
||||||
"default": 1
|
"default": 1
|
||||||
},
|
},
|
||||||
"order": {
|
"order": {
|
||||||
"name": "order",
|
"name": "order",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"default": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"comparison_dimensions_comparison_id_idx": {
|
||||||
|
"name": "comparison_dimensions_comparison_id_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "comparison_id",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
"foreignKeys": {
|
||||||
"comparison_dimensions_comparison_id_comparisons_id_fk": {
|
"comparison_dimensions_comparison_id_comparisons_id_fk": {
|
||||||
"name": "comparison_dimensions_comparison_id_comparisons_id_fk",
|
"name": "comparison_dimensions_comparison_id_comparisons_id_fk",
|
||||||
@@ -130,10 +147,27 @@
|
|||||||
"name": "order",
|
"name": "order",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true,
|
||||||
|
"default": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"comparison_items_comparison_id_idx": {
|
||||||
|
"name": "comparison_items_comparison_id_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "comparison_id",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
"foreignKeys": {
|
||||||
"comparison_items_comparison_id_comparisons_id_fk": {
|
"comparison_items_comparison_id_comparisons_id_fk": {
|
||||||
"name": "comparison_items_comparison_id_comparisons_id_fk",
|
"name": "comparison_items_comparison_id_comparisons_id_fk",
|
||||||
@@ -169,7 +203,7 @@
|
|||||||
"name": "user_id",
|
"name": "user_id",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": true
|
||||||
},
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"name": "title",
|
"name": "title",
|
||||||
@@ -181,17 +215,18 @@
|
|||||||
"name": "query",
|
"name": "query",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false
|
"notNull": true
|
||||||
},
|
},
|
||||||
"slug": {
|
"slug": {
|
||||||
"name": "slug",
|
"name": "slug",
|
||||||
"type": "varchar(255)",
|
"type": "text",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"name": "status",
|
"name": "status",
|
||||||
"type": "text",
|
"type": "comparison_status",
|
||||||
|
"typeSchema": "public",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true,
|
"notNull": true,
|
||||||
"default": "'researching'"
|
"default": "'researching'"
|
||||||
@@ -218,26 +253,26 @@
|
|||||||
"name": "is_public",
|
"name": "is_public",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": true,
|
||||||
"default": false
|
"default": true
|
||||||
},
|
},
|
||||||
"view_count": {
|
"view_count": {
|
||||||
"name": "view_count",
|
"name": "view_count",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": true,
|
||||||
"default": 0
|
"default": 0
|
||||||
},
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type": "timestamp",
|
"type": "timestamp with time zone",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true,
|
"notNull": true,
|
||||||
"default": "now()"
|
"default": "now()"
|
||||||
},
|
},
|
||||||
"updated_at": {
|
"updated_at": {
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type": "timestamp",
|
"type": "timestamp with time zone",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": true,
|
"notNull": true,
|
||||||
"default": "now()"
|
"default": "now()"
|
||||||
@@ -258,9 +293,53 @@
|
|||||||
"concurrently": false,
|
"concurrently": false,
|
||||||
"method": "btree",
|
"method": "btree",
|
||||||
"with": {}
|
"with": {}
|
||||||
|
},
|
||||||
|
"comparisons_slug_idx": {
|
||||||
|
"name": "comparisons_slug_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "slug",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
},
|
||||||
|
"comparisons_status_idx": {
|
||||||
|
"name": "comparisons_status_idx",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"expression": "status",
|
||||||
|
"isExpression": false,
|
||||||
|
"asc": true,
|
||||||
|
"nulls": "last"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isUnique": false,
|
||||||
|
"concurrently": false,
|
||||||
|
"method": "btree",
|
||||||
|
"with": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foreignKeys": {
|
||||||
|
"comparisons_user_id_users_id_fk": {
|
||||||
|
"name": "comparisons_user_id_users_id_fk",
|
||||||
|
"tableFrom": "comparisons",
|
||||||
|
"tableTo": "users",
|
||||||
|
"columnsFrom": [
|
||||||
|
"user_id"
|
||||||
|
],
|
||||||
|
"columnsTo": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"onDelete": "no action",
|
||||||
|
"onUpdate": "no action"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
"compositePrimaryKeys": {},
|
||||||
"uniqueConstraints": {
|
"uniqueConstraints": {
|
||||||
"comparisons_slug_unique": {
|
"comparisons_slug_unique": {
|
||||||
@@ -274,9 +353,84 @@
|
|||||||
"policies": {},
|
"policies": {},
|
||||||
"checkConstraints": {},
|
"checkConstraints": {},
|
||||||
"isRLSEnabled": false
|
"isRLSEnabled": false
|
||||||
|
},
|
||||||
|
"public.users": {
|
||||||
|
"name": "users",
|
||||||
|
"schema": "",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"name": "email",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"email_verified": {
|
||||||
|
"name": "email_verified",
|
||||||
|
"type": "timestamp with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"name": "image",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "timestamp with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "now()"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"name": "updated_at",
|
||||||
|
"type": "timestamp with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "now()"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {
|
||||||
|
"users_email_unique": {
|
||||||
|
"name": "users_email_unique",
|
||||||
|
"nullsNotDistinct": false,
|
||||||
|
"columns": [
|
||||||
|
"email"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"policies": {},
|
||||||
|
"checkConstraints": {},
|
||||||
|
"isRLSEnabled": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enums": {
|
||||||
|
"public.comparison_status": {
|
||||||
|
"name": "comparison_status",
|
||||||
|
"schema": "public",
|
||||||
|
"values": [
|
||||||
|
"researching",
|
||||||
|
"completed",
|
||||||
|
"failed"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"enums": {},
|
|
||||||
"schemas": {},
|
"schemas": {},
|
||||||
"sequences": {},
|
"sequences": {},
|
||||||
"roles": {},
|
"roles": {},
|
||||||
|
|||||||
@@ -5,8 +5,29 @@
|
|||||||
{
|
{
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"version": "7",
|
"version": "7",
|
||||||
"when": 1777066133958,
|
"when": 1777066297133,
|
||||||
"tag": "0000_opposite_doomsday",
|
"tag": "0000_gorgeous_puma",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1777066300000,
|
||||||
|
"tag": "0001_fix_email_verified",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 2,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1777066400000,
|
||||||
|
"tag": "0002_add_accounts_table",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 3,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1777066500000,
|
||||||
|
"tag": "0003_add_verifications_table",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,97 +1,94 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useState } from "react"
|
import { useState, useEffect, useCallback } from "react"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
import { Search, Eye, BarChart3, Filter, X, Loader2 } from "lucide-react"
|
import { Search, Eye, Filter, X, Loader2, RefreshCw } from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
|
||||||
const allComparisons = [
|
interface Comparison {
|
||||||
{
|
id: string
|
||||||
id: "1",
|
title: string
|
||||||
title: "React vs Vue vs Svelte",
|
summary: string
|
||||||
description: "Frontend framework comparison for modern web development",
|
slug: string
|
||||||
items: ["React", "Vue", "Svelte"],
|
tags: string[]
|
||||||
tags: ["Tech", "JavaScript"],
|
items: string[]
|
||||||
author: "Alex Johnson",
|
viewCount: number
|
||||||
overallScore: 8.5,
|
createdAt: string
|
||||||
views: 1247,
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "2",
|
|
||||||
title: "GPT-4 vs Claude vs Gemini",
|
|
||||||
description: "Comparing top AI language models for reasoning tasks",
|
|
||||||
items: ["GPT-4", "Claude 3", "Gemini Pro"],
|
|
||||||
tags: ["AI", "Products"],
|
|
||||||
author: "Sarah Chen",
|
|
||||||
overallScore: 8.8,
|
|
||||||
views: 3891,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "3",
|
|
||||||
title: "Notion vs Obsidian vs Roam",
|
|
||||||
description: "Knowledge management tools for productivity",
|
|
||||||
items: ["Notion", "Obsidian", "Roam Research"],
|
|
||||||
tags: ["Productivity", "Tools"],
|
|
||||||
author: "Mike Peters",
|
|
||||||
overallScore: 7.5,
|
|
||||||
views: 892,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "4",
|
|
||||||
title: "AWS vs GCP vs Azure",
|
|
||||||
description: "Cloud platform comparison for enterprise infrastructure",
|
|
||||||
items: ["AWS", "Google Cloud", "Microsoft Azure"],
|
|
||||||
tags: ["Tech", "Cloud"],
|
|
||||||
author: "Emma Wilson",
|
|
||||||
overallScore: 9.0,
|
|
||||||
views: 2156,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "5",
|
|
||||||
title: "iPhone 15 Pro vs Samsung S24 Ultra",
|
|
||||||
description: "Flagship smartphone comparison with camera and performance benchmarks",
|
|
||||||
items: ["iPhone 15 Pro", "Samsung S24 Ultra"],
|
|
||||||
tags: ["Products", "Mobile"],
|
|
||||||
author: "James Lee",
|
|
||||||
overallScore: 8.2,
|
|
||||||
views: 3421,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "6",
|
|
||||||
title: "Python vs Rust vs Go",
|
|
||||||
description: "Systems programming languages compared for performance and productivity",
|
|
||||||
items: ["Python", "Rust", "Go"],
|
|
||||||
tags: ["Tech", "Programming"],
|
|
||||||
author: "Anna Kim",
|
|
||||||
overallScore: 8.4,
|
|
||||||
views: 1873,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const categories = ["All", "Tech", "Products", "AI", "Cloud", "Productivity"]
|
interface ComparisonsResponse {
|
||||||
|
comparisons: Comparison[]
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
limit: number
|
||||||
|
}
|
||||||
|
|
||||||
export default function ExplorePage() {
|
export default function ExplorePage() {
|
||||||
const [searchQuery, setSearchQuery] = useState("")
|
const [comparisons, setComparisons] = useState<Comparison[]>([])
|
||||||
const [selectedCategory, setSelectedCategory] = useState("All")
|
const [total, setTotal] = useState(0)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [searchQuery, setSearchQuery] = useState("")
|
||||||
|
const [debouncedSearch, setDebouncedSearch] = useState("")
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState("All")
|
||||||
|
|
||||||
const filteredComparisons = allComparisons.filter((comparison) => {
|
const limit = 20
|
||||||
const matchesSearch =
|
|
||||||
searchQuery === "" ||
|
const fetchComparisons = useCallback(async (pageNum: number, search: string, append = false) => {
|
||||||
comparison.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
setLoading(true)
|
||||||
comparison.items.some((item) =>
|
setError(null)
|
||||||
item.toLowerCase().includes(searchQuery.toLowerCase())
|
try {
|
||||||
)
|
const params = new URLSearchParams({
|
||||||
|
page: pageNum.toString(),
|
||||||
|
limit: limit.toString(),
|
||||||
|
...(search && { search }),
|
||||||
|
})
|
||||||
|
const res = await fetch(`/api/comparisons?${params}`)
|
||||||
|
if (!res.ok) throw new Error("Failed to fetch comparisons")
|
||||||
|
const data: ComparisonsResponse = await res.json()
|
||||||
|
setComparisons(prev => append ? [...prev, ...data.comparisons] : data.comparisons)
|
||||||
|
setTotal(data.total)
|
||||||
|
setPage(pageNum)
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Something went wrong")
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setDebouncedSearch(searchQuery)
|
||||||
|
setPage(1)
|
||||||
|
fetchComparisons(1, searchQuery)
|
||||||
|
}, 300)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}, [searchQuery, fetchComparisons])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchComparisons(1, "")
|
||||||
|
}, [fetchComparisons])
|
||||||
|
|
||||||
|
const categories = ["All", ...Array.from(new Set(comparisons.flatMap(c => c.tags)))]
|
||||||
|
|
||||||
|
const filteredComparisons = comparisons.filter((comparison) => {
|
||||||
const matchesCategory =
|
const matchesCategory =
|
||||||
selectedCategory === "All" ||
|
selectedCategory === "All" ||
|
||||||
comparison.tags.some((tag) => tag.toLowerCase() === selectedCategory.toLowerCase())
|
comparison.tags.some((tag) => tag.toLowerCase() === selectedCategory.toLowerCase())
|
||||||
return matchesSearch && matchesCategory
|
return matchesCategory
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const loadMore = () => {
|
||||||
|
fetchComparisons(page + 1, debouncedSearch, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasMore = comparisons.length < total
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-6xl mx-auto p-4 sm:p-6 space-y-6">
|
<div className="max-w-6xl mx-auto p-4 sm:p-6 space-y-6">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
@@ -125,14 +122,44 @@ export default function ExplorePage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{loading ? (
|
{loading && comparisons.length === 0 ? (
|
||||||
<div className="flex items-center justify-center py-12">
|
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
<Loader2 className="size-8 animate-spin text-primary" />
|
{[...Array(6)].map((_, i) => (
|
||||||
|
<Card key={i} className="h-full">
|
||||||
|
<CardHeader className="pb-3">
|
||||||
|
<Skeleton className="h-5 w-3/4 mb-2" />
|
||||||
|
<Skeleton className="h-4 w-full" />
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-3">
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
<Skeleton className="h-5 w-12" />
|
||||||
|
<Skeleton className="h-5 w-12" />
|
||||||
</div>
|
</div>
|
||||||
|
<Skeleton className="h-4 w-full" />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : error ? (
|
||||||
|
<Card className="p-8 text-center">
|
||||||
|
<div className="flex flex-col items-center gap-4">
|
||||||
|
<div className="size-12 rounded-full bg-destructive/10 flex items-center justify-center">
|
||||||
|
<X className="size-6 text-destructive" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">Failed to load comparisons</p>
|
||||||
|
<p className="text-sm text-muted-foreground">{error}</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={() => fetchComparisons(page, debouncedSearch)} className="gap-2">
|
||||||
|
<RefreshCw className="size-4" />
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
) : filteredComparisons.length > 0 ? (
|
) : filteredComparisons.length > 0 ? (
|
||||||
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
{filteredComparisons.map((comparison) => (
|
{filteredComparisons.map((comparison) => (
|
||||||
<Link key={comparison.id} href={`/compare/${comparison.id}`}>
|
<Link key={comparison.id} href={`/compare/${comparison.slug}`}>
|
||||||
<Card className="h-full transition-all hover:border-primary hover:shadow-md">
|
<Card className="h-full transition-all hover:border-primary hover:shadow-md">
|
||||||
<CardHeader className="pb-3">
|
<CardHeader className="pb-3">
|
||||||
<div className="flex items-start justify-between gap-2">
|
<div className="flex items-start justify-between gap-2">
|
||||||
@@ -141,7 +168,7 @@ export default function ExplorePage() {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
</div>
|
</div>
|
||||||
<CardDescription className="text-sm line-clamp-2">
|
<CardDescription className="text-sm line-clamp-2">
|
||||||
{comparison.description}
|
{comparison.summary}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-3">
|
<CardContent className="space-y-3">
|
||||||
@@ -153,15 +180,6 @@ export default function ExplorePage() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
||||||
<Avatar className="size-6">
|
|
||||||
<AvatarFallback className="text-[10px]">
|
|
||||||
{comparison.author.split(" ").map((n) => n[0]).join("")}
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
<span className="text-xs">{comparison.author}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between pt-2 border-t">
|
<div className="flex items-center justify-between pt-2 border-t">
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-sm text-muted-foreground">
|
||||||
{comparison.items.join(" vs ")}
|
{comparison.items.join(" vs ")}
|
||||||
@@ -169,10 +187,7 @@ export default function ExplorePage() {
|
|||||||
<div className="flex items-center gap-3 text-sm">
|
<div className="flex items-center gap-3 text-sm">
|
||||||
<span className="flex items-center gap-1 text-muted-foreground">
|
<span className="flex items-center gap-1 text-muted-foreground">
|
||||||
<Eye className="size-3.5" />
|
<Eye className="size-3.5" />
|
||||||
{comparison.views.toLocaleString()}
|
{comparison.viewCount.toLocaleString()}
|
||||||
</span>
|
|
||||||
<span className="font-semibold text-foreground bg-primary/10 px-2 py-0.5 rounded">
|
|
||||||
{comparison.overallScore}/10
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -206,11 +221,19 @@ export default function ExplorePage() {
|
|||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{loading && comparisons.length > 0 && (
|
||||||
|
<div className="flex justify-center py-4">
|
||||||
|
<Loader2 className="size-6 animate-spin text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!loading && hasMore && (
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<Button variant="outline" className="gap-2">
|
<Button variant="outline" onClick={loadMore} className="gap-2">
|
||||||
Load More
|
Load More
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,66 +1,58 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from "react"
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { BarChart3, Eye, Calendar, Plus, ArrowRight } from "lucide-react"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
import { BarChart3, Eye, Calendar, Plus, ArrowRight, RefreshCw, LogIn } from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
import { useSession } from "@/lib/auth-client"
|
||||||
|
|
||||||
const mockUser = {
|
interface Comparison {
|
||||||
name: "Alex Johnson",
|
id: string
|
||||||
email: "alex@example.com",
|
title: string
|
||||||
avatar: "/placeholder-avatar.png",
|
slug: string
|
||||||
|
items: string[]
|
||||||
|
tags: string[]
|
||||||
|
viewCount: number
|
||||||
|
overallScore: number
|
||||||
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockComparisons = [
|
interface UserComparisonsResponse {
|
||||||
{
|
comparisons: Comparison[]
|
||||||
id: "1",
|
total: number
|
||||||
title: "React vs Vue vs Svelte",
|
page: number
|
||||||
items: ["React", "Vue", "Svelte"],
|
}
|
||||||
tags: ["Tech", "JavaScript"],
|
|
||||||
overallScore: 8.5,
|
|
||||||
views: 1247,
|
|
||||||
createdAt: "2024-01-15",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "2",
|
|
||||||
title: "GPT-4 vs Claude vs Gemini",
|
|
||||||
items: ["GPT-4", "Claude 3", "Gemini Pro"],
|
|
||||||
tags: ["AI", "Products"],
|
|
||||||
overallScore: 8.8,
|
|
||||||
views: 3891,
|
|
||||||
createdAt: "2024-01-10",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "3",
|
|
||||||
title: "Notion vs Obsidian vs Roam",
|
|
||||||
items: ["Notion", "Obsidian", "Roam Research"],
|
|
||||||
tags: ["Productivity"],
|
|
||||||
overallScore: 7.5,
|
|
||||||
views: 892,
|
|
||||||
createdAt: "2024-01-05",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const stats = [
|
interface UserStats {
|
||||||
{ label: "Total Comparisons", value: 12, icon: BarChart3 },
|
totalComparisons: number
|
||||||
{ label: "Total Views", value: "8.2K", icon: Eye },
|
totalViews: number
|
||||||
]
|
}
|
||||||
|
|
||||||
export default function ProfilePage() {
|
export default function ProfilePage() {
|
||||||
|
// TODO: Replace with real auth session data
|
||||||
|
const user = { name: "Demo User", email: "demo@example.com", avatar: "" }
|
||||||
|
const stats = [
|
||||||
|
{ label: "Comparisons", value: "0", icon: BarChart3 },
|
||||||
|
{ label: "Total Views", value: "0", icon: Eye },
|
||||||
|
]
|
||||||
|
const comparisons: Comparison[] = []
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-4xl mx-auto p-4 sm:p-6 space-y-8">
|
<div className="max-w-4xl mx-auto p-4 sm:p-6 space-y-8">
|
||||||
<div className="flex items-center gap-6">
|
<div className="flex items-center gap-6">
|
||||||
<Avatar className="size-20">
|
<Avatar className="size-20">
|
||||||
<AvatarImage src={mockUser.avatar} />
|
<AvatarImage src={user.avatar} />
|
||||||
<AvatarFallback className="text-2xl bg-primary/10 text-primary font-semibold">
|
<AvatarFallback className="text-2xl bg-primary/10 text-primary font-semibold">
|
||||||
{mockUser.name.split(" ").map((n) => n[0]).join("")}
|
{user.name.split(" ").map((n) => n[0]).join("")}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<h1 className="text-2xl font-bold">{mockUser.name}</h1>
|
<h1 className="text-2xl font-bold">{user.name}</h1>
|
||||||
<p className="text-muted-foreground">{mockUser.email}</p>
|
<p className="text-muted-foreground">{user.email}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -91,9 +83,9 @@ export default function ProfilePage() {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{mockComparisons.length > 0 ? (
|
{comparisons.length > 0 ? (
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
{mockComparisons.map((comparison) => (
|
{comparisons.map((comparison) => (
|
||||||
<Link key={comparison.id} href={`/compare/${comparison.id}`}>
|
<Link key={comparison.id} href={`/compare/${comparison.id}`}>
|
||||||
<Card className="h-full transition-all hover:border-primary hover:shadow-md">
|
<Card className="h-full transition-all hover:border-primary hover:shadow-md">
|
||||||
<CardHeader className="pb-3">
|
<CardHeader className="pb-3">
|
||||||
@@ -118,7 +110,7 @@ export default function ProfilePage() {
|
|||||||
<div className="flex items-center gap-3 text-sm text-muted-foreground">
|
<div className="flex items-center gap-3 text-sm text-muted-foreground">
|
||||||
<span className="flex items-center gap-1">
|
<span className="flex items-center gap-1">
|
||||||
<Eye className="size-3.5" />
|
<Eye className="size-3.5" />
|
||||||
{comparison.views.toLocaleString()}
|
{comparison.viewCount.toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
<span className="font-semibold text-foreground">
|
<span className="font-semibold text-foreground">
|
||||||
{comparison.overallScore}/10
|
{comparison.overallScore}/10
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export async function createComparison(formData: FormData) {
|
|||||||
|
|
||||||
await db.insert(comparisons).values({
|
await db.insert(comparisons).values({
|
||||||
id,
|
id,
|
||||||
|
userId: "system",
|
||||||
title,
|
title,
|
||||||
query,
|
query,
|
||||||
slug,
|
slug,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { db } from "@/lib/db";
|
|||||||
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { createId } from "@paralleldrive/cuid2";
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
|
import { auth } from "@/lib/auth";
|
||||||
|
|
||||||
function serializeSSE(event: string, data: unknown): string {
|
function serializeSSE(event: string, data: unknown): string {
|
||||||
return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
||||||
@@ -23,6 +24,11 @@ function slugify(text: string): string {
|
|||||||
// const ratelimit = new Ratelimit({ redis, limiter: slidingWindow(5, "1m") })
|
// const ratelimit = new Ratelimit({ redis, limiter: slidingWindow(5, "1m") })
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
|
const session = await auth.api.getSession({ headers: request.headers });
|
||||||
|
if (!session?.user) {
|
||||||
|
return Response.json({ error: "Authentication required" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
const body: { query?: string; items?: string[]; dimensions?: string[] } =
|
const body: { query?: string; items?: string[]; dimensions?: string[] } =
|
||||||
await request.json();
|
await request.json();
|
||||||
const { query, items, dimensions } = body;
|
const { query, items, dimensions } = body;
|
||||||
@@ -54,8 +60,9 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
await db.insert(comparisons).values({
|
await db.insert(comparisons).values({
|
||||||
id,
|
id,
|
||||||
|
userId: session.user.id,
|
||||||
title,
|
title,
|
||||||
query: query || null,
|
query: query ?? title,
|
||||||
slug,
|
slug,
|
||||||
status: "researching",
|
status: "researching",
|
||||||
});
|
});
|
||||||
|
|||||||
24
src/app/api/comparisons/[slug]/route.ts
Normal file
24
src/app/api/comparisons/[slug]/route.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons } from "@/lib/db/schema";
|
||||||
|
import { eq, sql } from "drizzle-orm";
|
||||||
|
import { getComparison } from "@/app/actions/comparison";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
_request: Request,
|
||||||
|
{ params }: { params: Promise<{ slug: string }> }
|
||||||
|
) {
|
||||||
|
const { slug } = await params;
|
||||||
|
|
||||||
|
await db
|
||||||
|
.update(comparisons)
|
||||||
|
.set({ viewCount: sql`${comparisons.viewCount} + 1` })
|
||||||
|
.where(eq(comparisons.slug, slug));
|
||||||
|
|
||||||
|
const comparison = await getComparison(slug);
|
||||||
|
|
||||||
|
if (!comparison) {
|
||||||
|
return Response.json({ error: "Not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json(comparison);
|
||||||
|
}
|
||||||
65
src/app/api/comparisons/route.ts
Normal file
65
src/app/api/comparisons/route.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
||||||
|
import { eq, and, desc, ilike, sql, inArray } from "drizzle-orm";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Math.max(1, Number(searchParams.get("page")) || 1);
|
||||||
|
const limit = Math.min(100, Math.max(1, Number(searchParams.get("limit")) || 20));
|
||||||
|
const search = searchParams.get("search") || "";
|
||||||
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
|
const conditions = [eq(comparisons.isPublic, true), eq(comparisons.status, "completed")];
|
||||||
|
if (search) {
|
||||||
|
conditions.push(ilike(comparisons.title, `%${search}%`));
|
||||||
|
}
|
||||||
|
|
||||||
|
const where = and(...conditions);
|
||||||
|
|
||||||
|
const [result, countResult] = await Promise.all([
|
||||||
|
db
|
||||||
|
.select()
|
||||||
|
.from(comparisons)
|
||||||
|
.where(where)
|
||||||
|
.orderBy(desc(comparisons.createdAt))
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset),
|
||||||
|
db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(comparisons)
|
||||||
|
.where(where),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const total = countResult[0].count;
|
||||||
|
|
||||||
|
const comparisonIds = result.map((c) => c.id);
|
||||||
|
const itemsMap: Record<string, string[]> = {};
|
||||||
|
|
||||||
|
if (comparisonIds.length > 0) {
|
||||||
|
const items = await db
|
||||||
|
.select({
|
||||||
|
comparisonId: comparisonItems.comparisonId,
|
||||||
|
name: comparisonItems.name,
|
||||||
|
})
|
||||||
|
.from(comparisonItems)
|
||||||
|
.where(inArray(comparisonItems.comparisonId, comparisonIds));
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
if (!itemsMap[item.comparisonId]) itemsMap[item.comparisonId] = [];
|
||||||
|
itemsMap[item.comparisonId].push(item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = result.map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
title: c.title,
|
||||||
|
summary: (c.summary || "").slice(0, 200),
|
||||||
|
slug: c.slug,
|
||||||
|
tags: c.tags || [],
|
||||||
|
items: itemsMap[c.id] || [],
|
||||||
|
viewCount: c.viewCount ?? 0,
|
||||||
|
createdAt: c.createdAt.toISOString(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
return Response.json({ comparisons: data, total, page, limit });
|
||||||
|
}
|
||||||
69
src/app/api/user/comparisons/route.ts
Normal file
69
src/app/api/user/comparisons/route.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons, comparisonItems } from "@/lib/db/schema";
|
||||||
|
import { eq, desc, sql, inArray } from "drizzle-orm";
|
||||||
|
import { auth } from "@/lib/auth";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const session = await auth.api.getSession({ headers: await headers() });
|
||||||
|
|
||||||
|
if (!session?.user) {
|
||||||
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Math.max(1, Number(searchParams.get("page")) || 1);
|
||||||
|
const limit = Math.min(100, Math.max(1, Number(searchParams.get("limit")) || 20));
|
||||||
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
|
const where = eq(comparisons.userId, session.user.id);
|
||||||
|
|
||||||
|
const [result, countResult] = await Promise.all([
|
||||||
|
db
|
||||||
|
.select()
|
||||||
|
.from(comparisons)
|
||||||
|
.where(where)
|
||||||
|
.orderBy(desc(comparisons.createdAt))
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset),
|
||||||
|
db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(comparisons)
|
||||||
|
.where(where),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const total = countResult[0].count;
|
||||||
|
|
||||||
|
const comparisonIds = result.map((c) => c.id);
|
||||||
|
const itemsMap: Record<string, string[]> = {};
|
||||||
|
|
||||||
|
if (comparisonIds.length > 0) {
|
||||||
|
const items = await db
|
||||||
|
.select({
|
||||||
|
comparisonId: comparisonItems.comparisonId,
|
||||||
|
name: comparisonItems.name,
|
||||||
|
})
|
||||||
|
.from(comparisonItems)
|
||||||
|
.where(inArray(comparisonItems.comparisonId, comparisonIds));
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
if (!itemsMap[item.comparisonId]) itemsMap[item.comparisonId] = [];
|
||||||
|
itemsMap[item.comparisonId].push(item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = result.map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
title: c.title,
|
||||||
|
summary: (c.summary || "").slice(0, 200),
|
||||||
|
slug: c.slug,
|
||||||
|
tags: c.tags || [],
|
||||||
|
items: itemsMap[c.id] || [],
|
||||||
|
viewCount: c.viewCount ?? 0,
|
||||||
|
status: c.status,
|
||||||
|
isPublic: c.isPublic,
|
||||||
|
createdAt: c.createdAt.toISOString(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
return Response.json({ comparisons: data, total, page, limit });
|
||||||
|
}
|
||||||
23
src/app/api/user/stats/route.ts
Normal file
23
src/app/api/user/stats/route.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons } from "@/lib/db/schema";
|
||||||
|
import { eq, sql } from "drizzle-orm";
|
||||||
|
import { auth } from "@/lib/auth";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const session = await auth.api.getSession({ headers: await headers() });
|
||||||
|
|
||||||
|
if (!session?.user) {
|
||||||
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db
|
||||||
|
.select({
|
||||||
|
totalComparisons: sql<number>`count(*)`,
|
||||||
|
totalViews: sql<number>`coalesce(sum(${comparisons.viewCount}), 0)`,
|
||||||
|
})
|
||||||
|
.from(comparisons)
|
||||||
|
.where(eq(comparisons.userId, session.user.id));
|
||||||
|
|
||||||
|
return Response.json(result[0]);
|
||||||
|
}
|
||||||
@@ -4,7 +4,10 @@ import { db } from "./db";
|
|||||||
import * as schema from "./db/schema";
|
import * as schema from "./db/schema";
|
||||||
|
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: drizzleAdapter(db, { provider: "pg", schema }),
|
database: drizzleAdapter(db, {
|
||||||
|
provider: "pg",
|
||||||
|
schema,
|
||||||
|
}),
|
||||||
emailAndPassword: { enabled: true },
|
emailAndPassword: { enabled: true },
|
||||||
session: { expiresIn: 60 * 60 * 24 * 7 },
|
session: { expiresIn: 60 * 60 * 24 * 7 },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
|
boolean,
|
||||||
|
index,
|
||||||
|
integer,
|
||||||
|
jsonb,
|
||||||
|
pgEnum,
|
||||||
pgTable,
|
pgTable,
|
||||||
text,
|
text,
|
||||||
timestamp,
|
timestamp,
|
||||||
jsonb,
|
|
||||||
integer,
|
|
||||||
boolean,
|
|
||||||
varchar,
|
|
||||||
index,
|
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
|
|
||||||
export const users = pgTable("users", {
|
export const users = pgTable("users", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
@@ -15,10 +16,43 @@ export const users = pgTable("users", {
|
|||||||
email: text("email").notNull().unique(),
|
email: text("email").notNull().unique(),
|
||||||
emailVerified: boolean("email_verified").default(false),
|
emailVerified: boolean("email_verified").default(false),
|
||||||
image: text("image"),
|
image: text("image"),
|
||||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const accounts = pgTable("accounts", {
|
||||||
|
id: text("id").primaryKey().$defaultFn(() => createId()),
|
||||||
|
userId: text("user_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => users.id, { onDelete: "cascade" }),
|
||||||
|
accountId: text("account_id").notNull(),
|
||||||
|
providerId: text("provider_id").notNull(),
|
||||||
|
accessToken: text("access_token"),
|
||||||
|
refreshToken: text("refresh_token"),
|
||||||
|
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
||||||
|
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
||||||
|
scope: text("scope"),
|
||||||
|
idToken: text("id_token"),
|
||||||
|
password: text("password"),
|
||||||
|
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||||
|
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const verifications = pgTable("verifications", {
|
||||||
|
id: text("id").primaryKey().$defaultFn(() => createId()),
|
||||||
|
identifier: text("identifier").notNull(),
|
||||||
|
value: text("value").notNull(),
|
||||||
|
expiresAt: timestamp("expires_at").notNull(),
|
||||||
|
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
|
||||||
|
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const comparisonStatusEnum = pgEnum("comparison_status", [
|
||||||
|
"researching",
|
||||||
|
"completed",
|
||||||
|
"failed",
|
||||||
|
]);
|
||||||
|
|
||||||
export const sessions = pgTable("sessions", {
|
export const sessions = pgTable("sessions", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
@@ -26,36 +60,46 @@ export const sessions = pgTable("sessions", {
|
|||||||
.references(() => users.id, { onDelete: "cascade" }),
|
.references(() => users.id, { onDelete: "cascade" }),
|
||||||
token: text("token").notNull().unique(),
|
token: text("token").notNull().unique(),
|
||||||
expiresAt: timestamp("expires_at").notNull(),
|
expiresAt: timestamp("expires_at").notNull(),
|
||||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
ipAddress: text("ip_address"),
|
||||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
userAgent: text("user_agent"),
|
||||||
|
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||||
|
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const comparisons = pgTable(
|
export const comparisons = pgTable(
|
||||||
"comparisons",
|
"comparisons",
|
||||||
{
|
{
|
||||||
id: text("id").primaryKey(),
|
id: text("id")
|
||||||
userId: text("user_id"),
|
.primaryKey()
|
||||||
title: text("title").notNull(),
|
.$defaultFn(() => createId()),
|
||||||
query: text("query"),
|
userId: text("user_id")
|
||||||
slug: varchar("slug", { length: 255 }).notNull().unique(),
|
|
||||||
status: text("status", {
|
|
||||||
enum: ["researching", "completed", "failed"],
|
|
||||||
})
|
|
||||||
.notNull()
|
.notNull()
|
||||||
.default("researching"),
|
.references(() => users.id),
|
||||||
|
title: text("title").notNull(),
|
||||||
|
query: text("query").notNull(),
|
||||||
|
slug: text("slug").notNull().unique(),
|
||||||
|
status: comparisonStatusEnum("status").notNull().default("researching"),
|
||||||
summary: text("summary"),
|
summary: text("summary"),
|
||||||
overallData: jsonb("overall_data"),
|
overallData: jsonb("overall_data"),
|
||||||
tags: text("tags").array(),
|
tags: text("tags").array(),
|
||||||
isPublic: boolean("is_public").default(false),
|
isPublic: boolean("is_public").notNull().default(true),
|
||||||
viewCount: integer("view_count").default(0),
|
viewCount: integer("view_count").notNull().default(0),
|
||||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => [index("comparisons_user_id_idx").on(table.userId)]
|
(table) => [
|
||||||
|
index("comparisons_user_id_idx").on(table.userId),
|
||||||
|
index("comparisons_slug_idx").on(table.slug),
|
||||||
|
index("comparisons_status_idx").on(table.status),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
export const comparisonItems = pgTable("comparison_items", {
|
export const comparisonItems = pgTable(
|
||||||
id: text("id").primaryKey(),
|
"comparison_items",
|
||||||
|
{
|
||||||
|
id: text("id")
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => createId()),
|
||||||
comparisonId: text("comparison_id")
|
comparisonId: text("comparison_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => comparisons.id, { onDelete: "cascade" }),
|
.references(() => comparisons.id, { onDelete: "cascade" }),
|
||||||
@@ -66,22 +110,24 @@ export const comparisonItems = pgTable("comparison_items", {
|
|||||||
scores: jsonb("scores"),
|
scores: jsonb("scores"),
|
||||||
pros: text("pros").array(),
|
pros: text("pros").array(),
|
||||||
cons: text("cons").array(),
|
cons: text("cons").array(),
|
||||||
order: integer("order").notNull(),
|
order: integer("order").notNull().default(0),
|
||||||
});
|
},
|
||||||
|
(table) => [index("comparison_items_comparison_id_idx").on(table.comparisonId)],
|
||||||
|
);
|
||||||
|
|
||||||
export const comparisonDimensions = pgTable("comparison_dimensions", {
|
export const comparisonDimensions = pgTable(
|
||||||
id: text("id").primaryKey(),
|
"comparison_dimensions",
|
||||||
|
{
|
||||||
|
id: text("id")
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => createId()),
|
||||||
comparisonId: text("comparison_id")
|
comparisonId: text("comparison_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => comparisons.id, { onDelete: "cascade" }),
|
.references(() => comparisons.id, { onDelete: "cascade" }),
|
||||||
name: text("name").notNull(),
|
name: text("name").notNull(),
|
||||||
description: text("description"),
|
description: text("description"),
|
||||||
weight: integer("weight").default(1),
|
weight: integer("weight").notNull().default(1),
|
||||||
order: integer("order").notNull(),
|
order: integer("order").notNull().default(0),
|
||||||
});
|
},
|
||||||
|
(table) => [index("comparison_dimensions_comparison_id_idx").on(table.comparisonId)],
|
||||||
export type Comparison = typeof comparisons.$inferSelect;
|
);
|
||||||
export type NewComparison = typeof comparisons.$inferInsert;
|
|
||||||
export type ComparisonItem = typeof comparisonItems.$inferSelect;
|
|
||||||
export type NewComparisonItem = typeof comparisonItems.$inferInsert;
|
|
||||||
export type ComparisonDimension = typeof comparisonDimensions.$inferSelect;
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ Use the web research data above to provide factual, data-driven insights. Refere
|
|||||||
|
|
||||||
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
||||||
try {
|
try {
|
||||||
const response = await client.chat.completions.create({
|
const response = await getClient().chat.completions.create({
|
||||||
model: "gpt-4o-mini",
|
model: "gpt-4o-mini",
|
||||||
messages: [
|
messages: [
|
||||||
{ role: "system", content: SYSTEM_PROMPT },
|
{ role: "system", content: SYSTEM_PROMPT },
|
||||||
|
|||||||
Reference in New Issue
Block a user