-
Notifications
You must be signed in to change notification settings - Fork 54
Malu's API gets Reviewed #30
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
base: master
Are you sure you want to change the base?
Changes from all commits
a85508a
6b262dc
99ecd9b
8620bc4
5de736a
2570e82
a9533d1
9be8dbe
4f32d68
4a4a5e5
f2f07b7
992c517
849614b
5105058
0822eac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This is my documentation! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| function index(req, res) { | ||
| res.json({ | ||
| message: 'Welcome to Cliffly!', | ||
| documentation_url: 'https://github.com/MaluPalu/express-personal-api/blob/master/DOCUMENTATION.md', | ||
| base_url: 'https://evening-beach-72520.herokuapp.com/', | ||
| endpoints: [ | ||
| {method: "GET", path: "/api", description: "Describes all available endpoints"}, | ||
| {method: "GET", path: "/api/profile", description: "Describes all available endpoints"}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your profile doesn't describe available endpoints, it describes you! |
||
| {method: "GET", path: "/api/cliffs", description: "List Cliff jumping specifiations"}, | ||
| {method: "POST", path: "/api/cliffs", description: "Add Cliff jumping specifiations"}, | ||
| {method: "PUT", path: "/api/cliffs/:id", description: "Update Cliff jumping specifiations"}, | ||
| {method: "DELETE", path: "/api/cliffs/:id", description: "Delete Cliff jumping specifiations"}, | ||
| {method: "GET", path: "/api/cliffs/:id", description: "Individual Cliff jumping specifiations"} | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| index: index | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| let db = require('../models'); | ||
| // controllers/cliffsController.js | ||
| // GET /api/cliffs | ||
| function index(req, res) { | ||
| // send back all cliffs as JSON | ||
| db.Cliff.find(function(err, albums){ | ||
| if (err) { | ||
| console.log("index error" + err); | ||
| res.sendStatus(500); | ||
| } | ||
| res.send(albums); | ||
| }); | ||
| } | ||
|
|
||
| // POST /api/cliffs | ||
| function create(req, res) { | ||
| //create cliff using form data from req parameter | ||
| var newCliff = new db.Cliff({ | ||
| name: req.body.cliffName, | ||
| nearestCity: req.body.nearestCity, | ||
| gpsCoords: req.body.gpsCoords, | ||
| height: req.body.height, | ||
| accessibility: req.body.accessibility, | ||
| description: req.body.description | ||
| }); | ||
| // add that cliff to the database | ||
| newCliff.save(function(err, cliff){ | ||
| if (err) { | ||
| console.log("create error: " + err); | ||
| return; | ||
| } | ||
| console.log("created", cliff.name); | ||
| res.json(cliff); | ||
| }); | ||
| } | ||
|
|
||
| // GET /api/cliffs/:cliffId | ||
| function retrieve(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused function. you can get rid of this. |
||
| } | ||
|
|
||
| // DELETE /api/cliffs/:cliffId | ||
| function destroy(req, res) { | ||
| console.log(req.params.id); | ||
| db.Cliff.findByIdAndRemove(req.params.id, (err, Cliff) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, you'd use lower-case |
||
| console.log(Cliff); | ||
| if (err) { | ||
| console.log(err); | ||
| } | ||
| Cliff.save(function(err, cliff) { | ||
| console.log("hi"); | ||
| if (err) { | ||
| console.log(err); | ||
| } | ||
| let response = { | ||
| message: "Cliff successfully deleted", | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation 😭 |
||
| res.status(200).send(response); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| function update(req, res) { | ||
| db.Cliff.findById(req.params.id, function(err, foundCliff) { | ||
| if (err) { | ||
| console.log('err', err); | ||
| return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if there's an error, you should send a response. |
||
| } | ||
| foundCliff.set({ | ||
| name: req.body.cliffName, | ||
| nearestCity: req.body.nearestCity, | ||
| gpsCoords: req.body.gpsCoords, | ||
| height: req.body.height, | ||
| acessibility: req.body.accessibility, | ||
| description: req.body.description, | ||
| }); | ||
| foundCliff.save(function(err, updateCliff) { | ||
| if (err) { | ||
| console.log(err); | ||
| } | ||
| console.log('update cliff', updateCliff); | ||
| res.json(updateCliff); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| module.exports = { | ||
| index: index, | ||
| create: create, | ||
| retrieve: retrieve, | ||
| destroy: destroy, | ||
| update: update | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module.exports = { | ||
| api: require('./apiController'), | ||
| cliffs: require('./cliffController') | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| var mongoose = require('mongoose'), | ||
| Schema = mongoose.Schema; | ||
|
|
||
| var CliffSchema = new Schema({ | ||
| name: String, | ||
| nearestCity: String, | ||
| gpsCoords: String, | ||
| height: String, | ||
| acessibility: String, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're missing a c in accessibility--that's why it never saves correctly. |
||
| description: String | ||
| }); | ||
|
|
||
| var Cliff = mongoose.model('Cliff', CliffSchema); | ||
|
|
||
| module.exports = Cliff; | ||
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.
haha, OK! But your documentation should be in your README.md file.