diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b9e94f9 Binary files /dev/null and b/.DS_Store differ diff --git a/.eslintrc.json b/.eslintrc.json index 0058df2..0388195 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,6 +13,7 @@ "consistent-return": 0, "no-param-reassign": 0, "comma-dangle": 0, + "class-methods-use-this": ["off"], "curly": ["error", "multi-line"], "import/no-unresolved": [2, { "commonjs": true }], "no-shadow": ["error", { "allow": ["req", "res", "err"] }], diff --git a/server/app.js b/server/app.js index 5f2e64e..9714c90 100644 --- a/server/app.js +++ b/server/app.js @@ -13,11 +13,6 @@ app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); -// app.use('/', routes) - routes(app); - -// app.use('/', routes); - export default app; diff --git a/server/controllers/recipes.js b/server/controllers/recipes.js new file mode 100644 index 0000000..e992aaa --- /dev/null +++ b/server/controllers/recipes.js @@ -0,0 +1,134 @@ +import recipes from '../models/Recipes'; + +/** + * @class RecipeController + */ +class RecipeController { + /** + * creates new recipe + * @param {object} req expres req object + * @param {object} res exp res object + * @returns {json} json + * @memberof RecipeController + */ + postRecipe(req, res) { + const id = recipes.length + 1; + const { author } = req.body; + const { title } = req.body; + const created = new Date(); + const { description } = req.body; + const ingredients = req.body.ingredients.split(','); + + // validation to ensure all fields are available + if (!author) { + return res.status(400).send('Recipe has no author.'); + } + + if (!title) { + return res.status(400).send('Recipe has no title.'); + } + + if (!ingredients) { + return res.status(400).send('Recipe has no ingredients.'); + } + + if (!description) { + return res.status(400).send('Recipe has no description.'); + } + + const newRecipe = { + id, + author, + title, + created, + ingredients: [ingredients], + description, + votes: 0, + reviews: [] + }; + + recipes.push(newRecipe); + + return res.status(201).json({ + status: 'success', + message: 'Recipe added', + recipe: recipes + }); + } + + /** + * edit new recipe + * @param {object} req expres req object + * @param {object} res exp res object + * @returns {json} json + * @memberof RecipeController + */ + editRecipe(req, res) { + const { id } = req.params; + let editRecipe; + + recipes.forEach((recipe) => { + if (recipe.id === parseInt(id, 10)) { + recipe.title = req.body.title || recipe.title; + recipe.ingredients = + req.body.ingredients.split(',') || recipe.ingredients; + recipe.description = req.body.description || recipe.description; + + editRecipe = recipe; + } + }); + if (editRecipe) { + return res.status(200).json({ + status: 'success', + message: 'Recipe modified', + recipe: editRecipe + }); + } + return res.status(404).send(`recipe with id ${id} not found`); + } + + /** + * delete recipe + * @param {object} req expres req object + * @param {object} res exp res object + * @returns {json} json + * @memberof RecipeController + */ + deleteRecipe(req, res) { + const { id } = req.params; + + recipes.forEach((recipe) => { + if (recipe.id === parseInt(id, 10)) { + const newRecipes = recipes.filter(data => data.id !== parseInt(id, 10)); + return res.status(200).json({ + status: 'success', + message: 'Recipe deleted', + recipe: newRecipes + }); + } + }); + } + + /** + * delete recipe + * @param {object} req expres req object + * @param {object} res exp res object + * @returns {json} json + * @memberof RecipeController + */ + getAllRecipes(req, res) { + if (req.query.sort === 'upvotes' && req.query.order === 'des') { + return res.status(200).json({ + status: 'success', + recipes: recipes.sort((a, b) => b.votes - a.votes) + }); + } + return res.status(200).json({ + status: 'success', + recipes + + }); + } +} + +export default RecipeController; diff --git a/server/models/Recipes.js b/server/models/Recipes.js new file mode 100644 index 0000000..38ebdb9 --- /dev/null +++ b/server/models/Recipes.js @@ -0,0 +1,67 @@ +const recipes = [ + { + id: 1, + author: 'Michael', + title: 'Tomato Stew', + created: 1508833829, + ingredients: ['tomato', 'pepper', 'onions', 'rice'], + description: 'lorem ispum lorem ispum lorem ispum loremispum', + votes: 23, + reviews: [ + { + user: 'john', + created: 1508833829, + review: 'nice recipe' + }, + { + user: 'Seun', + created: 1508833859, + content: 'beautiful recipe. will definately try this one.' + } + ], + + }, + + { + id: 2, + author: 'Cynthis', + title: 'Spagethi meat balls', + created: 1508833829, + ingredients: ['tomato', 'pepper', 'onions', 'rice'], + description: 'lorem ispum lorem ispum lorem ispum loremispum', + votes: 5, + reviews: [ + { + user: 'mike', + created: 1508833829, + comment: 'nice recipe' + }, + ], + + }, + + { + id: 3, + author: 'Bayo', + title: 'Afang', + created: 1508833829, + ingredients: ['afang', 'waterleave', 'onions'], + description: 'lorem ispum lorem ispum lorem ispum loremispum', + votes: 12, + reviews: [ + { + user: 'Nkoyo', + created: 1508833839, + content: 'wow nice soup.' + }, + { + user: 'Seun', + created: 1508833859, + content: 'beautiful recipe.' + } + ], + + } +]; + +export default recipes; diff --git a/server/routes.js b/server/routes.js index bb8af08..5b45e89 100644 --- a/server/routes.js +++ b/server/routes.js @@ -1,9 +1,19 @@ - - +import * as Recipe from './controllers/recipes'; const recipe = new Recipe.default(); +const routes = (app) => { + // post recipe route + app.post('/api/v1/recipes', recipe.postRecipe); + + // edit recipe + app.put('/api/v1/recipes/:id', recipe.editRecipe); + // delete recipe + app.delete('/api/v1/recipes/:id', recipe.deleteRecipe); + // Get all recipes + app.get('/api/v1/recipes', recipe.getAllRecipes); +}; export default routes; diff --git a/template/.DS_Store b/template/.DS_Store new file mode 100644 index 0000000..32b40e0 Binary files /dev/null and b/template/.DS_Store differ diff --git a/template/css/style.css b/template/css/style.css new file mode 100644 index 0000000..f874a81 --- /dev/null +++ b/template/css/style.css @@ -0,0 +1,136 @@ +body { + +} + +header { + background: url(../img/lope.jpg); + background-size: contain; +} + +.nav-item a{ + color: #ffffff !important; +} +.brand a{ + font-size: 4em; + font-family: 'Lobster', cursive; + color: #1FBBEF !important; +} + +.jumbotron { + padding: 7rem 5rem; + background-color: transparent; + color:#ffffff; +} +.jumbotron h2 { + + font-size:3em; +} + +.recipeButton { + background-color: #1FBBEF; + border-color: #1FBBEF; +} + +.recipes { + margin-top: 2rem; + margin-bottom: 2rem; +} + + +@media (max-width: 991px) { + .jumbotron { + padding: 0; + padding-top: 5rem 2rem; + + } + .jumbotron h2 { + font-size: 2em; + } + +} + +.card .btn-action { + margin: -23px 20px -23px auto; + background-color: #1FBBEF; + height: 47px; + width: 47px; + line-height: 0; +} + +.btn-floating { + z-index: 1; + overflow: hidden; + padding: 0; + border-radius: 50%; + + -webkit-transition: .3s; + transition: .3s; +} + +.card .btn-action .fa.fa-chevron-right { + margin-top: 2px; + margin-left: 2px; +} + +.btn-floating i { + width: inherit; + font-size: 1.25rem; + line-height: 47px; + text-align: center; +} + +.btn-floating i { + display: inline-block; + color: #fff; +} + +.card .card-data { + background-color: #1FBBEF; + color: #fff; + text-align: center; + height: auto; + padding: 10px; +} + +.card .card-data ul { + margin-bottom: 0; + font-size: .9rem; +} + +.card .card-data ul li { + display: inline; + color: white; + padding: 1rem; +} + +hr { + border-top: 2px solid #1FBBEF; +} + +.cta { + background-color: #F8F9FD; + + padding: 3rem; +} + +footer{ + background-color: black; + color: white; + padding: 2rem; +} + +footer .brand a { + font-size: 3em !important; + text-decoration: none; + margin: auto; +} + +footer ul { + padding: 0px; +} + +footer ul li { + list-style: none; +} + + diff --git a/template/img/food.jpeg b/template/img/food.jpeg new file mode 100644 index 0000000..d46bc92 Binary files /dev/null and b/template/img/food.jpeg differ diff --git a/template/img/lope.jpg b/template/img/lope.jpg new file mode 100644 index 0000000..7a639b3 Binary files /dev/null and b/template/img/lope.jpg differ diff --git a/template/index.html b/template/index.html new file mode 100644 index 0000000..c7e1e98 --- /dev/null +++ b/template/index.html @@ -0,0 +1,477 @@ + + + + + + + + More Recipe + + + + + + + +
+
+ + + +
+

The best recipes in the world come from real people like you

+

Collaborate with the community, get reviews, earn votes while showcasing your awesome recipe.

+ +
+ +
+ +
+ +
+

Popular Recipes

+
+ + +
+ + +
+
+ +
+ +
+ + +
+
+
+ + + + + + +
+ +

Baked Ziti I +

+
+ +

Lorem ispum lorem ispum lorem ispim lorem ispum lorem ispim lorem sosos fmffmfnod kdoe lorem ispum lorem ispulm + lssumr. +

+
+ +

By + Michael Umanah +

+
+ + + +
+
    +
  • + 05/10/2015
  • +
  • + + 12 +
  • +
  • + + 210 +
  • + +
+
+ + +
+ + +
+ +
+
+ +
+ + +
+
+
+ + + + + + +
+ +

Baked Ziti I +

+
+ +

Lorem ispum lorem ispum lorem ispim lorem ispum lorem ispim lorem sosos fmffmfnod kdoe lorem ispum lorem ispulm + lssumr. +

+
+ +

By + Michael Umanah +

+
+ + + +
+
    +
  • + 05/10/2015
  • +
  • + + 12 +
  • +
  • + + 210 +
  • + +
+
+ + +
+ +
+ +
+
+ +
+ + +
+
+
+ + + + + + +
+ +

Baked Ziti I +

+
+ +

Lorem ispum lorem ispum lorem ispim lorem ispum lorem ispim lorem sosos fmffmfnod kdoe lorem ispum lorem ispulm + lssumr. +

+
+ +

By + Michael Umanah +

+
+ + + +
+
    +
  • + 05/10/2015
  • +
  • + + 12 +
  • +
  • + + 210 +
  • + +
+
+ + +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+
+ + + + + + +
+ +

Baked Ziti I +

+
+ +

Lorem ispum lorem ispum lorem ispim lorem ispum lorem ispim lorem sosos fmffmfnod kdoe lorem ispum lorem ispulm + lssumr. +

+
+ +

By + Michael Umanah +

+
+ + + +
+
    +
  • + 05/10/2015
  • +
  • + + 12 +
  • +
  • + + 210 +
  • + +
+
+ + +
+ + +
+ +
+
+ +
+ + +
+
+
+ + + + + + +
+ +

Baked Ziti I +

+
+ +

Lorem ispum lorem ispum lorem ispim lorem ispum lorem ispim lorem sosos fmffmfnod kdoe lorem ispum lorem ispulm + lssumr. +

+
+ +

By + Michael Umanah +

+
+ + + +
+
    +
  • + 05/10/2015
  • +
  • + + 12 +
  • +
  • + + 210 +
  • + +
+
+ + +
+ +
+ +
+
+ +
+ + +
+
+
+ + + + + + +
+ +

Baked Ziti I +

+
+ +

Lorem ispum lorem ispum lorem ispim lorem ispum lorem ispim lorem sosos fmffmfnod kdoe lorem ispum lorem ispulm + lssumr. +

+
+ +

By + Michael Umanah +

+
+ + + + +
+
    +
  • + 05/10/2015
  • +
  • + + 12 +
  • +
  • + + 210 +
  • + +
+
+ + +
+ +
+
+ +
+ +
+

Do you have a beautiful Recipe

+

Share it with the world and get awesome feedbacks

+ +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/template/js/script.js b/template/js/script.js new file mode 100644 index 0000000..e69de29