Initial food blog app
This commit is contained in:
24
app/api/restaurants/route.ts
Normal file
24
app/api/restaurants/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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 })
|
||||
}
|
||||
Reference in New Issue
Block a user