Initial food blog app

This commit is contained in:
Andy
2026-03-21 11:57:08 +00:00
commit b83762bfc3
33 changed files with 8621 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { NextResponse } from 'next/server'
import { readRestaurants, writeRestaurants } from '@/app/lib/restaurants'
import { Restaurant } from '@/app/types'
export async function GET(
_request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
const restaurants = readRestaurants()
const restaurant = restaurants.find((r) => r.id === id)
if (!restaurant) {
return NextResponse.json({ error: 'Not found' }, { status: 404 })
}
return NextResponse.json(restaurant)
}
export async function PUT(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
const body = await request.json() as Partial<Restaurant>
const restaurants = readRestaurants()
const index = restaurants.findIndex((r) => r.id === id)
if (index === -1) {
return NextResponse.json({ error: 'Not found' }, { status: 404 })
}
restaurants[index] = { ...restaurants[index], ...body, id }
writeRestaurants(restaurants)
return NextResponse.json(restaurants[index])
}
export async function DELETE(
_request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params
const restaurants = readRestaurants()
const filtered = restaurants.filter((r) => r.id !== id)
if (filtered.length === restaurants.length) {
return NextResponse.json({ error: 'Not found' }, { status: 404 })
}
writeRestaurants(filtered)
return NextResponse.json({ success: true })
}