Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEI-24 Vincent #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recipes":[{"title":"IOREUTOPIWU","ingredients":";SGN","instructions":"DNB;SZ"}]}
87 changes: 87 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const jsonfile = require("jsonfile");

const file = "data.json";

const express = require("express");

const app = express();

app.use(express.static(__dirname+"/public"));

app.use(express.json());

app.use(express.urlencoded({
extended: true,
}));

const methodOverride = require("method-override");

app.use(methodOverride("_method"));

const reactEngine = require("express-react-views").createEngine();

app.engine("jsx", reactEngine);

app.set("views", __dirname + "/views");

app.set("view engine", "jsx");

app.get("/recipes/new", (request, response) => {
response.render("form")
})

app.post("/recipes", (request, response) => {
jsonfile.readFile("data.json", (err, obj) => {
obj.recipes.push(request.body)
jsonfile.writeFile("data.json", obj)
response.render("home", obj)
})
})

app.get("/recipes/:id", (request, response) => {
jsonfile.readFile("data.json", (err, obj) => {
let index = request.params.id;
let showRecipe = {...obj.recipes[index], "id":index};
response.render("view", showRecipe);
})
})

app.get("/recipes/", (request, response) => {
jsonfile.readFile("data.json", (err, obj) => {
response.render("home", obj)
})

})

app.get('/recipes/:id/edit', (request,response)=>{
jsonfile.readFile('data.json',(err,obj)=>{
let index = request.params.id;
let data = {...obj.recipes[index], "id":index};
response.render("edit",data)
})
})

app.put("/recipes/:id", (request, response) => {
jsonfile.readFile("data.json", (err, obj) => {
let index = request.params.id;
let updateRecipe = obj.recipes[index]
updateRecipe.ingredients = request.body.ingredients;
updateRecipe.instructions = request.body.instructions;
jsonfile.writeFile("data.json", obj)
let display = obj.recipes[request.params.id]
response.render("view", display)
})
})

app.delete("/recipes/:id", (request, response) => {
jsonfile.readFile("data.json", (err, obj) => {
let index = parseInt(request.params.id)
obj.recipes.splice(index, 1)
jsonfile.writeFile("data.json", obj)
response.send("DELETED!");
})
})

app.listen(3000, () => {
console.log("3000 is working")
})
1 change: 1 addition & 0 deletions node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/css-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/editorconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/html-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jsesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/loose-envify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nopt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/regjsparser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading