Initial food blog app
This commit is contained in:
26
app/api/restaurants/[id]/visits/[visitId]/route.ts
Normal file
26
app/api/restaurants/[id]/visits/[visitId]/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { readRestaurants, writeRestaurants } from '@/app/lib/restaurants'
|
||||
|
||||
export async function DELETE(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string; visitId: string }> }
|
||||
) {
|
||||
const { id, visitId } = await params
|
||||
const restaurants = readRestaurants()
|
||||
const index = restaurants.findIndex((r) => r.id === id)
|
||||
|
||||
if (index === -1) {
|
||||
return NextResponse.json({ error: 'Restaurant not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
const visitIndex = restaurants[index].visits.findIndex((v) => v.id === visitId)
|
||||
|
||||
if (visitIndex === -1) {
|
||||
return NextResponse.json({ error: 'Visit not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
restaurants[index].visits.splice(visitIndex, 1)
|
||||
writeRestaurants(restaurants)
|
||||
|
||||
return NextResponse.json({ success: true })
|
||||
}
|
||||
Reference in New Issue
Block a user