Skip to content

Commit 7c8711d

Browse files
committed
Popular Recipes #New Feature
1 parent 5672068 commit 7c8711d

14 files changed

+182
-200
lines changed

app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const weekMenusRoutes = require("./routes/weekMenusRoutes");
99
const fridgeRoutes = require("./routes/fridgeRoutes");
1010
const tagRoutes = require("./routes/tagRoutes");
1111
const recipeRoutes = require("./routes/recipeRoutes");
12+
const dbRoutes = require("./routes/db");
13+
const { db } = require("./models/recipes/recipeModel");
1214

1315
const app = express();
1416

@@ -26,5 +28,6 @@ app.post("/mealList", weekMenusRoutes);
2628
app.post("/ingredientList", fridgeRoutes);
2729
app.post("/randomList", tagRoutes);
2830
app.get("/recipe/:mealId", recipeRoutes);
31+
app.post("/savedRecipe", dbRoutes);
2932

30-
module.exports = app;
33+
module.exports = app;

models/recipes/recipeModel.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const mongoose = require("mongoose");
22

33
const recipesSchema = new mongoose.Schema({
4-
name: {
5-
type: String,
6-
required: true,
7-
},
8-
image: {
9-
type: String,
10-
required: true,
11-
},
12-
id: {
13-
type: String,
14-
required: true,
15-
},
16-
time: {
17-
type: String,
18-
}
4+
name: {
5+
type: String,
6+
required: true,
7+
},
8+
image: {
9+
type: String,
10+
required: true,
11+
},
12+
id: {
13+
type: String,
14+
required: true,
15+
},
16+
time: {
17+
type: String,
18+
},
1919
});
2020

21-
const Recipe = mongoose.model('Recipe', recipesSchema);
21+
const Recipe = mongoose.model("Recipe", recipesSchema);
2222

23-
module.exports = Recipe;
23+
module.exports = Recipe;

routes/db.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const express = require("express");
2+
const router = express.Router();
3+
const Recipe = require("../models/recipes/recipeModel");
4+
5+
router.post("/savedRecipe", (req, res) => {
6+
try {
7+
const recipe = new Recipe({
8+
name: req.body.name,
9+
image: req.body.image,
10+
id: req.body.id,
11+
time: req.body.time,
12+
});
13+
14+
recipe.save();
15+
res.send("Recipe saved successfully!");
16+
} catch (error) {
17+
res.send(error);
18+
}
19+
});
20+
21+
module.exports = router;

routes/recipeRoutes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ router.get("/recipe/:mealId", async (req, res) => {
3636
summary: striptags(summary.summary),
3737
analyzedInstructions: info.analyzedInstructions,
3838
ingredients: ingredientsData.ingredients,
39+
id: mealId,
3940
});
4041
// res.send(summary.summary);
4142
});

routes/viewsRoutes.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const express = require("express");
22
const router = express.Router();
3+
const Recipe = require("../models/recipes/recipeModel");
34

45
router.get("/", (req, res) => {
56
res.render("home");
@@ -17,5 +18,19 @@ router.get("/inputRandom", (req, res) => {
1718
res.render("inputRandom");
1819
});
1920

21+
router.get("/trendingRecipes", async (req, res) => {
22+
try {
23+
const recipe = await Recipe.find();
24+
if (!recipe) {
25+
return res.status(404).send("Recipes not found");
26+
} else {
27+
res.render("trendingRecipes", {
28+
recipes: recipe,
29+
});
30+
}
31+
} catch (error) {
32+
res.status(500).send(error);
33+
}
34+
});
2035

21-
module.exports = router;
36+
module.exports = router;

views/home.ejs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
1515
</head>
1616
<body class="homeBody">
17-
18-
19-
20-
21-
<!--nav-->
17+
<!--nav-->
2218
<nav x-data="{show:false}" class="flex items-center justify-between flex-wrap bg-orange-600 p-6 navShadow">
2319
<div class="flex items-center flex-shrink-0 text-white mr-6">
2420
<span class="font-semibold text-xl tracking-tight">FoodMeets</span>

views/inputIngredient.ejs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,19 @@
1515

1616
<body class="font-mono bg-gray-400">
1717
<!--nav-->
18-
<nav
19-
x-data="{show:false}"
20-
class="flex items-center justify-between flex-wrap bg-orange-600 p-6"
21-
>
18+
<nav x-data="{show:false}" class="flex items-center justify-between flex-wrap bg-orange-600 p-6">
2219
<div class="flex items-center flex-shrink-0 text-white mr-6">
2320
<span class="font-semibold text-xl tracking-tight">FoodMeets</span>
2421
</div>
2522
<div class="block md:hidden">
26-
<button
27-
@click="show=!show"
28-
class="flex items-center px-3 py-2 border rounded text-gray-100 border-gray-200 hover:text-white hover:border-white"
29-
>
30-
<svg
31-
class="fill-current h-3 w-3"
32-
viewBox="0 0 20 20"
33-
xmlns="http://www.w3.org/2000/svg"
34-
>
35-
<title>Menu</title>
36-
<path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z" />
37-
</svg>
23+
<button @click="show=!show" class="flex items-center px-3 py-2 border rounded text-gray-100 border-gray-200 hover:text-white hover:border-white">
24+
<svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
3825
</button>
3926
</div>
40-
<div
41-
@click.away="show = false"
42-
:class="{ 'block': show, 'hidden': !show }"
43-
class="w-full block flex-grow md:flex md:justify-end md:w-auto"
44-
>
27+
<div @click.away="show = false" :class="{ 'block': show, 'hidden': !show }" class="w-full block flex-grow md:flex md:justify-end md:w-auto">
4528
<div>
46-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Compose Post</a> -->
47-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Dashboard</a> -->
48-
<a
49-
href="/"
50-
class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0"
51-
>Home</a
52-
>
29+
<a href="/trendingRecipes" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Popular</a>
30+
<a href="/" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0">Home</a>
5331
</div>
5432
</div>
5533
</nav>

views/inputRandom.ejs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,19 @@
1515

1616
<body class="font-mono bg-gray-400">
1717
<!--nav-->
18-
<nav
19-
x-data="{show:false}"
20-
class="flex items-center justify-between flex-wrap bg-orange-600 p-6"
21-
>
18+
<nav x-data="{show:false}" class="flex items-center justify-between flex-wrap bg-orange-600 p-6">
2219
<div class="flex items-center flex-shrink-0 text-white mr-6">
2320
<span class="font-semibold text-xl tracking-tight">FoodMeets</span>
2421
</div>
2522
<div class="block md:hidden">
26-
<button
27-
@click="show=!show"
28-
class="flex items-center px-3 py-2 border rounded text-gray-100 border-gray-200 hover:text-white hover:border-white"
29-
>
30-
<svg
31-
class="fill-current h-3 w-3"
32-
viewBox="0 0 20 20"
33-
xmlns="http://www.w3.org/2000/svg"
34-
>
35-
<title>Menu</title>
36-
<path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z" />
37-
</svg>
23+
<button @click="show=!show" class="flex items-center px-3 py-2 border rounded text-gray-100 border-gray-200 hover:text-white hover:border-white">
24+
<svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
3825
</button>
3926
</div>
40-
<div
41-
@click.away="show = false"
42-
:class="{ 'block': show, 'hidden': !show }"
43-
class="w-full block flex-grow md:flex md:justify-end md:w-auto"
44-
>
27+
<div @click.away="show = false" :class="{ 'block': show, 'hidden': !show }" class="w-full block flex-grow md:flex md:justify-end md:w-auto">
4528
<div>
46-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Compose Post</a> -->
47-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Dashboard</a> -->
48-
<a
49-
href="/"
50-
class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0"
51-
>Home</a
52-
>
29+
<a href="/trendingRecipes" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Popular</a>
30+
<a href="/" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0">Home</a>
5331
</div>
5432
</div>
5533
</nav>

views/inputWeekPlanMeals.ejs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,23 @@
1111
</head>
1212

1313
<body class="font-mono bg-gray-400">
14-
15-
16-
<!--nav-->
17-
<nav x-data="{show:false}" class="flex items-center justify-between flex-wrap bg-orange-600 p-6">
18-
<div class="flex items-center flex-shrink-0 text-white mr-6">
19-
<span class="font-semibold text-xl tracking-tight">FoodMeets</span>
20-
</div>
21-
<div class="block md:hidden">
22-
<button @click="show=!show" class="flex items-center px-3 py-2 border rounded text-gray-100 border-gray-200 hover:text-white hover:border-white">
23-
<svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
24-
</button>
25-
</div>
26-
<div @click.away="show = false" :class="{ 'block': show, 'hidden': !show }" class="w-full block flex-grow md:flex md:justify-end md:w-auto">
27-
<div>
28-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Compose Post</a> -->
29-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Dashboard</a> -->
30-
<a href="/" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0">Home</a>
31-
</div>
14+
<!--nav-->
15+
<nav x-data="{show:false}" class="flex items-center justify-between flex-wrap bg-orange-600 p-6">
16+
<div class="flex items-center flex-shrink-0 text-white mr-6">
17+
<span class="font-semibold text-xl tracking-tight">FoodMeets</span>
18+
</div>
19+
<div class="block md:hidden">
20+
<button @click="show=!show" class="flex items-center px-3 py-2 border rounded text-gray-100 border-gray-200 hover:text-white hover:border-white">
21+
<svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
22+
</button>
23+
</div>
24+
<div @click.away="show = false" :class="{ 'block': show, 'hidden': !show }" class="w-full block flex-grow md:flex md:justify-end md:w-auto">
25+
<div>
26+
<a href="/trendingRecipes" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Popular</a>
27+
<a href="/" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0">Home</a>
3228
</div>
33-
</nav>
29+
</div>
30+
</nav>
3431

3532
<br>
3633
<form class="max-w-sm mx-auto", method="post" , action="/mealList">

views/planMeals.ejs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
</div>
3737
<div @click.away="show = false" :class="{ 'block': show, 'hidden': !show }" class="w-full block flex-grow md:flex md:justify-end md:w-auto">
3838
<div>
39-
<!-- <a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Compose Post</a> -->
40-
<a href="#" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Dashboard</a>
39+
<a href="/trendingRecipes" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-white border-white hover:border-transparent hover:text-orange-500 hover:bg-white mt-4 md:mt-0">Popular</a>
4140
<a href="/" class="block md:inline-block text-lg px-4 py-2 leading-none rounded text-orange border-white hover:border-transparent bg-white mt-4 md:mt-0">Home</a>
4241
</div>
4342
</div>

0 commit comments

Comments
 (0)