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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**/node_modules
node_modules
17 changes: 17 additions & 0 deletions controllers/apiControllers.js
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",

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.

endpoints: [
{
method: "GET", path: "/api", description: "Describes available endpoints"
}
]
});
}

module.exports = {
index:index
}
55 changes: 55 additions & 0 deletions controllers/bjjControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Copy link

Choose a reason for hiding this comment

The 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) {
Copy link

Choose a reason for hiding this comment

The 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 review rather than reviews

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) {
Copy link

Choose a reason for hiding this comment

The 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
}
5 changes: 5 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// requiring controllers
module.exports = {
api: require('./apiControllers'),
bjj: require('./bjjControllers')
};
14 changes: 14 additions & 0 deletions models/bjj.js
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;
10 changes: 0 additions & 10 deletions models/campsite.js.example

This file was deleted.

4 changes: 4 additions & 0 deletions models/index.js
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;
Loading