Initial commit: DrinkTracker full-stack app
Next.js 14 drink collection tracker with AI-powered search, menu scanning, ratings, wishlist, sharing, and CSV backup/restore. Features: - Auth (credentials + OAuth ready) - Drink collection with ratings and reviews - AI search via Claude/OpenAI with search history - Menu photo scanning with AI extraction - Wishlist / Try Later system - Public sharing via slug URLs - CSV backup and restore (merge/replace modes) - Docker Compose for Postgres + MinIO + dev server Security: docker-compose files use env var interpolation instead of hardcoded secrets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
60
src/app/api/settings/backup/route.ts
Normal file
60
src/app/api/settings/backup/route.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { auth } from "@/lib/auth"
|
||||
import { prisma } from "@/lib/prisma"
|
||||
import { generateBackupCsv } from "@/lib/backup"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
export async function GET() {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
||||
}
|
||||
|
||||
const userId = session.user.id
|
||||
|
||||
try {
|
||||
const [drinks, ratings, wishlistItems, preferences, sharedLists] =
|
||||
await Promise.all([
|
||||
prisma.drink.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
prisma.rating.findMany({
|
||||
where: { userId },
|
||||
include: { drink: { select: { name: true } } },
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
prisma.wishlistItem.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
prisma.userPreference.findUnique({ where: { userId } }),
|
||||
prisma.sharedList.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
])
|
||||
|
||||
const csv = generateBackupCsv(
|
||||
drinks,
|
||||
ratings,
|
||||
wishlistItems,
|
||||
preferences,
|
||||
sharedLists
|
||||
)
|
||||
|
||||
const date = new Date().toISOString().split("T")[0]
|
||||
|
||||
return new Response(csv, {
|
||||
headers: {
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Content-Disposition": `attachment; filename="drinktracker-backup-${date}.csv"`,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Backup export error:", error)
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to generate backup" },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user