Files
food/app/api/restaurants/route.ts
2026-03-21 11:57:08 +00:00

25 lines
662 B
TypeScript

import { NextResponse } from 'next/server'
import { readRestaurants, writeRestaurants } from '@/app/lib/restaurants'
import { Restaurant } from '@/app/types'
export async function GET() {
const restaurants = readRestaurants()
return NextResponse.json(restaurants)
}
export async function POST(request: Request) {
const body = await request.json() as Omit<Restaurant, 'id' | 'visits'>
const restaurants = readRestaurants()
const newRestaurant: Restaurant = {
...body,
id: crypto.randomUUID(),
visits: [],
}
restaurants.push(newRestaurant)
writeRestaurants(restaurants)
return NextResponse.json(newRestaurant, { status: 201 })
}