25 lines
662 B
TypeScript
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 })
|
|
}
|