Initial food blog app
This commit is contained in:
18
app/lib/restaurants.ts
Normal file
18
app/lib/restaurants.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { Restaurant } from '@/app/types'
|
||||
|
||||
const DATA_FILE = path.join(process.cwd(), 'data', 'restaurants.json')
|
||||
|
||||
export function readRestaurants(): Restaurant[] {
|
||||
try {
|
||||
const raw = fs.readFileSync(DATA_FILE, 'utf-8')
|
||||
return JSON.parse(raw) as Restaurant[]
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export function writeRestaurants(restaurants: Restaurant[]): void {
|
||||
fs.writeFileSync(DATA_FILE, JSON.stringify(restaurants, null, 2), 'utf-8')
|
||||
}
|
||||
Reference in New Issue
Block a user