Skip to content

Commit a4743b4

Browse files
committed
add restaurants route
1 parent 127f184 commit a4743b4

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

app.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const cors = require('cors')
66

77
const indexRouter = require('./routes/index');
88
const usersRouter = require('./routes/users');
9-
const postsRouter = require('./routes/posts')
10-
const productRouter = require('./routes/products')
9+
const postsRouter = require('./routes/posts');
10+
const productRouter = require('./routes/products');
11+
const restaurantsRouter = require('./routes/restaurants');
1112

1213
const app = express();
1314

@@ -22,5 +23,6 @@ app.use('/', indexRouter);
2223
app.use('/users', usersRouter);
2324
app.use('/posts', postsRouter);
2425
app.use('/products', productRouter)
26+
app.use('/restaurants', restaurantsRouter)
2527

2628
module.exports = app;

database/restaurants.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
1111
"id": "051d81107a55faa819fbfa41409d155a930fda40",
12-
"name": "Pizza Inn",
12+
"restaurant_name": "Pizza Inn",
1313
"place_id": "ChIJ3Uuv9x8XLxgRQVM21qXjvZ0",
1414
"price_level": 2,
1515
"average_rating": 4.1,
@@ -37,7 +37,7 @@
3737
},
3838
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
3939
"id": "5a9a202fc80bb0cc995462b3c2d2b22093af73e9",
40-
"name": "Creamy Inn-Parklands",
40+
"restaurant_name": "Creamy Inn-Parklands",
4141
"place_id": "ChIJYa5q9x8XLxgRCEp4BQSVVjA",
4242
"average_rating": 3.3,
4343
"ratings":[
@@ -64,7 +64,7 @@
6464
},
6565
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
6666
"id": "0e49e1f29b829a3e6c0e399cc4b6316c0715da9d",
67-
"name": "My Shop-Parklands",
67+
"restaurant_name": "My Shop-Parklands",
6868
"place_id": "ChIJn6Vj-h8XLxgRs-qT2FfOt9E",
6969
"average_rating": 2.5,
7070
"ratings":[

routes/restaurants.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const fs = require('fs')
4+
const restaurants = JSON.parse(fs.readFileSync('database/restaurants.json', 'utf-8'))
5+
6+
// GET Restaurants
7+
router.get('/', function (req, res, _next) {
8+
res.json(restaurants)
9+
});
10+
11+
12+
module.exports = router;

0 commit comments

Comments
 (0)