Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }],
Expand Down
5 changes: 0 additions & 5 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
134 changes: 134 additions & 0 deletions server/controllers/recipes.js
Original file line number Diff line number Diff line change
@@ -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;
67 changes: 67 additions & 0 deletions server/models/Recipes.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 12 additions & 2 deletions server/routes.js
Original file line number Diff line number Diff line change
@@ -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;
Binary file added template/.DS_Store
Binary file not shown.
136 changes: 136 additions & 0 deletions template/css/style.css
Original file line number Diff line number Diff line change
@@ -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;
}


Binary file added template/img/food.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added template/img/lope.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading