Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/node_modules

node_modules
16 changes: 16 additions & 0 deletions controllers/apiController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function index(req, res) {
res.json({
message: "Welcome to my personal API!",
documentation_url: "https://github.com/jcheng305/express-personal-api",
base_url: "localhost:3000",
endpoints: [
{
method: "GET", path: "/api", description: "Describes available endpoints"
}
]
});
}

module.exports = {
index: index
}
4 changes: 4 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
api: require('./apiController'),
lists: require('./motorcycleListController')
}
87 changes: 87 additions & 0 deletions controllers/motorcycleList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/***********
* DATABASE *
************/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add something like this to grab all your models/database tables:

var db = require('../models');


/* hard-coded data */
var motorcycleLists = [];

motorcycleLists.push({
_id: 132,
make: 'BMW',
model: 'S1000RR',
image: '/images/s1000rr.jpg',
releaseDate: '2009 to current',
weight: '403 lbs',
maxPower: '199 hp at 13,500 rpm',
maxTorque: '83 lb.-ft. at 10,500 rpm',
engineDisplacement: '999 cc'
});
motorcycleLists.push({
_id: 133,
make: 'Honda',
model: 'CBR1000RR',
image: '/images/cbr1000rr.jpg',
releaseDate: '2008 to current',
weight: '439 lbs',
maxPower: '153.4 hp at 10,700 rpm',
maxTorque: '78.74 lb.-ft. at 9,400 rpm',
engineDisplacement: '999 cc'
});
motorcycleLists.push({
_id: 134,
make: 'Triumph',
model: 'Daytona 675R',
image: '/images/675r.jpg',
releaseDate: '2006 to current',
weight: '363 lbs',
maxPower: '104 hp at 13,500 rpm',
maxTorque: '53 lb.-ft. at 10,500 rpm',
engineDisplacement: '674 cc'
})
motorcycleLists.push({
_id: 135,
make: 'Suzuki',
model: 'GSX-R 750',
image: '/images/gsxr750.jpg',
releaseDate: '2011 to current',
weight: '418 lbs',
maxPower: '148 hp at 12,800 rpm',
maxTorque: '64 lb.-ft. at 11,200 rpm',
engineDisplacement: '749 cc'
});

// GET /api/albums
function index(req, res) {
// send back all albums as JSON
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add something like this to grab data from your database, probably need to add data into the database first or seed it?

db.Profile.find({}, function(err, dataReturned) {
res.json(dataReturned);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// POST /api/albums
function create(req, res) {
// create an album based on request body and send it back as JSON
}

// GET /api/albums/:albumId
function show(req, res) {
// find one album by id and send it back as JSON
}

// DELETE /api/albums/:albumId
function destroy(req, res) {
// find one album by id, delete it, and send it back as JSON
}

// PUT or PATCH /api/albums/:albumId
function update(req, res) {
// find one album by id, update it based on request body,
// and send it back as JSON
}


// export public methods here
module.exports = {
index: index,
create: create,
show: show,
destroy: destroy,
update: update
};
Binary file added models/.DS_Store
Binary file not shown.
10 changes: 0 additions & 10 deletions models/campsite.js.example

This file was deleted.

6 changes: 6 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ mongoose.connect( process.env.MONGODB_URI || "mongodb://localhost/personal-api",
mongoose.Promise = global.Promise; // use native Promise

// module.exports.Campsite = require("./campsite.js.example");


const Profile = require('./profile');


module.exports.Profile = require("./profile.js");
28 changes: 28 additions & 0 deletions models/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// var mongoose = require('mongoose'),
// const Schema = mongoose.Schema;

// var CampsiteSchema = new Schema({
// description: String
// });

// var Campsite = mongoose.model('Campsite', CampsiteSchema);

// module.exports = Campsite;

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

const ProfileSchema = new Schema ({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is data about a motorcycle; why is it in a file called Profile?

make: String,
model: String,
image: String,
releaseDate: String,
weight: String,
maxPower: String,
maxTorque: String,
engineDisplacement: String
});

const Profile = mongoose.model('Profile', ProfileSchema);

module.exports = Profile;
Loading