-
Notifications
You must be signed in to change notification settings - Fork 54
Bryan Reese #35
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?
Bryan Reese #35
Changes from all commits
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| **/node_modules | ||
| node_modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| function index(req, res) { | ||
| res.json({ | ||
| message: "Welcome to BJJ reviews!", | ||
| description: "This is a app that allows people to read reviews on Brazilian Jiu Jitsu Academy", | ||
| documentation_url: "https://github.com/breese8009/express-personal-api", | ||
| base_url: "localhost:4000", | ||
| endpoints: [ | ||
| { | ||
| method: "GET", path: "/api", description: "Describes available endpoints" | ||
| } | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| index:index | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
|
|
||
|
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. file name should just be bjjController.js, singular |
||
| var db = require('../models'); | ||
|
|
||
| function index(req, res) { | ||
|
|
||
| db.Bjj.find({}, function(err, allAlbums) { | ||
| res.json(allAlbums); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| // create function to create data in database | ||
| function create(req, res) { | ||
| console.log('body', req.body); | ||
|
|
||
|
|
||
| db.Bjj.create(req.body, function(err, reviews) { | ||
|
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. This gives back a singular, not a plural, so should probably have the variable name |
||
| console.log(reviews); | ||
| if (err) { console.log('error', err); } | ||
| console.log(reviews); | ||
| res.json(reviews); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| // get data input by id | ||
| function show(req, res) { | ||
| // find one gym by id and send it back as JSON | ||
| console.log(req.params.bjjId); | ||
| db.Bjj.findById(req.params.bjjId, function(err, foundAlbum) { | ||
|
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. album 😭 |
||
|
|
||
| if(err) { console.log('albumsController.show error', err); } | ||
| console.log('albumsController.show responding with', foundAlbum); | ||
| res.json(foundAlbum); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function destroy(req, res) { | ||
|
|
||
|
|
||
| db.Bjj.findByIdAndRemove({_id: req.params.bjjId}, (err, response) => { | ||
|
|
||
| res.status(200).send(response); | ||
| console.log("shit did work: buh bye") | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| index: index, | ||
| create: create, | ||
| show: show, | ||
| destroy: destroy | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // requiring controllers | ||
| module.exports = { | ||
| api: require('./apiControllers'), | ||
| bjj: require('./bjjControllers') | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // mongodb scheme for database | ||
| var mongoose = require('mongoose'), | ||
| Schema = mongoose.Schema; | ||
|
|
||
| var bjjSchema = new Schema({ | ||
| gymName: String, | ||
| gymLocation: String, | ||
| image: String, | ||
| reviews: String | ||
| }); | ||
|
|
||
| var Bjj = mongoose.model('Bjj', bjjSchema); | ||
|
|
||
| module.exports = Bjj; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // connect to mongodb and mongoose | ||
| var mongoose = require("mongoose"); | ||
| mongoose.connect( process.env.MONGODB_URI || "mongodb://localhost/personal-api", {useMongoClient: true}); | ||
| mongoose.Promise = global.Promise; // use native Promise | ||
|
|
||
| // module.exports.Campsite = require("./campsite.js.example"); | ||
| var Bjj = require('./bjj'); | ||
|
|
||
| module.exports.Bjj = Bjj; |
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.
Had to use different port.