-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.js
75 lines (66 loc) · 2.04 KB
/
Menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require("express")
const port = 6000
const Menu = [
{id :1, meal: "Fufu and Egusi Soup"},
{id :2, meal: "Fried-Rice and Chicken"},
{id :3, meal: "Beans and Plantain"},
{id :4, meal: "Pounded-Yam and Vegetable Soup"},
{id :5, meal: "Yam Porridge and Fried Fish"},
{id :6, meal: "Moi-Moi and Pap"},
{id :7, meal: "Ofe Nsala and Semovita"},
{id :8, meal: "Jollof Rice and Fish Sauce"},
];
const app = express();
app.use(express.json());
app.get("/", (req, res) =>{
res.send("Welcome To OOPs Restaurant");
});
// All Available Meal On The Menu
app.get("/api/Menu", (req, res) =>{
res.send(Menu);
});
// Get A Single Meal From The Menu
app.get("/api/Menu/:id", (req, res) =>{
const meal = Menu.find((food) => food.id ===parseInt(req.params.id))
if (!meal) {
res.status(404).send(`Meal not found in the Menu: ${req.params.id}`);
} else {
res.send(meal)}
});
// Create A New Meal In The Menu
app.post("/api/Menu", (req, res) =>{
if (!req.body.meal){
res.send("please add")
} else {
const newRecipe = {
id: Menu.length + 1,
meal: req.body.meal
}
Menu.push(newRecipe)
res.send(Menu)}
});
// Update The Menu
app.put("/api/Menu/:id", (req, res) =>{
const meal = Menu.find((food) =>food.id ===parseInt(req.params.id))
if (meal) {
res.status(404).send(`Meal not found in the Menu: ${req.params.id}`)
if (!req.body.meal) {
res.send("please add")}
else {
meal.meal = req.body.meal
res.send(Menu)}
}
});
// Delete A Meal From The Menu
app.delete("/api/Menu/:id", (req, res) =>{
const meal = Menu.find((food) => food.id ===parseInt(req.params.id))
if (!meal) {
res.status(404).send(`Meal not found in the Menu: ${req.params.id}`);
} else {
res.send(meal)}
Menu.splice(meal,3)
res.send(Menu)
});
app.listen(port, () => {
console.log(`server is listening on port: $(port)`)
});