-
Notifications
You must be signed in to change notification settings - Fork 8
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
Finished hw #6
Open
LehmanBrother
wants to merge
9
commits into
ga-chicago:master
Choose a base branch
from
LehmanBrother:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Finished hw #6
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7a409f
Commit 1 - My server is set up and running
LehmanBrother d5260bc
Commit 2 - Connected my database, can see json in the browser
LehmanBrother a6c5927
Commit 3 - index.ejs view rendered at pokemon route
LehmanBrother 6e045de
Commit 4 - show view shows pokemon details
LehmanBrother b2c331d
Commits 6 and 7 - set up serving of static files, styled app
LehmanBrother 6e13433
reconfigured to use controller format
LehmanBrother e466761
new pokemon
LehmanBrother 3e96355
edit and delete
LehmanBrother 154d38a
added delete to show page
LehmanBrother File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
const Pokemon = require('../models/pokemon'); | ||
|
||
//index route | ||
router.get('/', (req,res) => { | ||
res.render('index.ejs', { | ||
pokemon: Pokemon | ||
}); | ||
}) | ||
|
||
//new route | ||
router.get('/new', (req,res) => { | ||
res.render('new.ejs'); | ||
}) | ||
|
||
//post route | ||
router.post('/',(req,res) => { | ||
Pokemon.push(req.body); | ||
res.redirect('/pokemon'); | ||
}) | ||
|
||
//show route | ||
router.get('/:id', (req,res) => { | ||
res.render('show.ejs', { | ||
pokemon: Pokemon[req.params.id], | ||
id: req.params.id | ||
}) | ||
}) | ||
|
||
//delete route | ||
router.delete('/:id', (req,res) => { | ||
Pokemon.splice(req.params.id,1); | ||
res.redirect('/pokemon'); | ||
}) | ||
|
||
//edit route | ||
router.get('/:id/edit', (req,res) => { | ||
res.render('edit.ejs', { | ||
pokemon: Pokemon[req.params.id], | ||
index: req.params.id | ||
}) | ||
}) | ||
|
||
//update route | ||
router.put('/:id', (req,res) => { | ||
Pokemon[req.params.id] = req.body; | ||
res.redirect('/pokemon'); | ||
}) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const pokemon = [ | ||
{ | ||
name: "Bulbasaur", | ||
img: "http://img.pokemondb.net/artwork/bulbasaur.jpg" | ||
}, | ||
{ | ||
name: "Ivysaur", | ||
img: "http://img.pokemondb.net/artwork/ivysaur.jpg" | ||
}, | ||
{ | ||
name: "Venusaur", | ||
img: "http://img.pokemondb.net/artwork/venusaur.jpg" | ||
}, | ||
{ | ||
name: "Charmander", | ||
img: "http://img.pokemondb.net/artwork/charmander.jpg" | ||
}, | ||
{ | ||
name: "Charizard", | ||
img: "http://img.pokemondb.net/artwork/charizard.jpg" | ||
}, | ||
{ | ||
name: "Squirtle", | ||
img: "http://img.pokemondb.net/artwork/squirtle.jpg" | ||
}, | ||
{ | ||
name: "Wartortle", | ||
img: "http://img.pokemondb.net/artwork/wartortle.jpg" | ||
} | ||
]; | ||
|
||
module.exports = pokemon; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background-color: cornsilk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
const bodyParser = require('body-parser'); | ||
const methodOverride = require('method-override'); | ||
const pokemonController = require('./controllers/pokemon'); | ||
|
||
//middleware | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
app.use(methodOverride('_method')); | ||
app.use('/pokemon', pokemonController); | ||
app.use(express.static('public')); | ||
|
||
app.get('/',(req, res) => { | ||
res.send('This is the server responding to a get request') | ||
}) | ||
|
||
app.listen(3000, () => { | ||
console.log('server is listening on port 3000'); | ||
}) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>Pokemon Editor</h1> | ||
<form method="POST" action="/pokemon/<%=index%>?_method=PUT"> | ||
Name: <input type="text" name="name" value="<%=pokemon.name%>"><br/> | ||
Image: <input type="text" name="img" value="<%=pokemon.img%>"><br/> | ||
<input type="submit" name="" value="Submit Edits"/> | ||
</form> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Pokemon Index</title> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> | ||
<link rel="stylesheet" type="text/css" href="/style.css"> | ||
<style> | ||
li {font-family: roboto;} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Pokemon Index</h1> | ||
<ul class="pokemon"> | ||
<% for(let i = 0; i < pokemon.length; i++) {%> | ||
<li> | ||
<a href='/pokemon/<%=i%>'><%= pokemon[i].name %></a> | ||
<form action='/pokemon/<%=i%>?_method=DELETE' method="POST"> | ||
<input type="submit" value="delete"/> | ||
</form> | ||
<a href='/pokemon/<%=i%>/edit'>Edit</a> | ||
</li> | ||
<% }%> | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>New Pokemon Page</h1> | ||
|
||
<form action="/pokemon" method="POST"> | ||
Name: <input type="text" name="name"><br/> | ||
Image: <input type="text" name="img"><br/> | ||
<input type="submit"> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>Pokemon Show Page</h1> | ||
<a href='/pokemon'>Index</a> | ||
<p>Name: <%= pokemon.name%></p> | ||
<img src="<%=pokemon.img%>"/> | ||
<form action='/pokemon/<%=id%>?_method=DELETE' method="POST"> | ||
<input type="submit" value="Delete"/> | ||
</form> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd recommend organizing this file a little more carefully. have a separate section for controllers and put all your controller stuff there (even though they are implemented the same way middleware is). example: