← back to Wine Finder Next
app/api/wines/[id]/route.ts
22 lines
// app/api/wines/[id]/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { getWineById, getWinePriceHistory } from '@/lib/wines';
type Params = { params: Promise<{ id: string }> };
export async function GET(_req: NextRequest, { params }: Params) {
const { id: paramId } = await params;
const id = Number(paramId);
if (Number.isNaN(id)) {
return NextResponse.json({ error: 'Invalid id' }, { status: 400 });
}
const wine = getWineById(id);
if (!wine) {
return NextResponse.json({ error: 'Not found' }, { status: 404 });
}
const history = getWinePriceHistory(id, 365);
return NextResponse.json({ wine, history });
}