//server.js

//Base setup 
// =========================================================================
// call the packages we need 
var express     = require('express');       // call express
var app         = express();                // define our app using express
var bodyParser  = require('body-parser');

//configure app to use body-parser()
//this will let us get data from a POST 
app.use(bodyParser.urlencoded({ extended : true}));
app.use(bodyParser.json());

var port = process.env.PORT || 8080;        //set our port 

var mongoose = require('mongoose');
mongoose.connect('mongodb://developer:developer@ds053838.mongolab.com:53838/diskover-db');

var Bear        = require('./app/models/bear');

//Routes for our API 
// ==========================================================================
var router = express.Router();

//middleware to use for all the requests
router.use(function(req, res, next) {
  //do logging
  console.log('- API request received');
  next(); //make sure we go to the next routes and we do not stop here
});

// test route to make sure everything is working (accessed at GET http://localhost:8080/api)
router.get('/', function(req, res) {
    res.json({ message: 'hooray! welcome to our api!' });   
});

// more routes for our API will happen here

// on routes that end in /bears
// ===========================================================================
router.route('/bears')
  // create a bear (accessed at POST http://localhost:8080/api/bears)
  .post(function(req, res) {
  
    var bear = new Bear();      // create a new instance of the bear model
    bear.name = req.body.name;  // set the bears name (comes from the request)
    
    console.log('INSERT: ' + req.body.name);
  
    // save the bear and check for errors
    bear.save(function(err){
      if(err)
          res.send(err);
      
      res.json({ message: 'Bear created!'});
    });
  })

  .get(function(req, res) {
    Bear.find(function(err, bears){
      if (err)
        res.send(err);
      
      res.json(bears);
    });
  });

// on routes that end in /bears/:bear_id
// ----------------------------------------------------
router.route('/bears/:bear_id')

    // get the bear with that id (accessed at GET http://localhost:8080/api/bears/:bear_id)
    .get(function(req, res) {
        Bear.findById(req.params.bear_id, function(err, bear) {
            if (err)
                res.send(err);
            res.json(bear);
        });
    })
    
    // update the bear with this id (accessed at PUT http://localhost:8080/api/bears/:bear_id)
    .put(function(req, res) {

        // use our bear model to find the bear we want
        Bear.findById(req.params.bear_id, function(err, bear) {

            if (err)
                res.send(err);

            bear.name = req.body.name;  // update the bears info

            // save the bear
            bear.save(function(err) {
                if (err)
                    res.send(err);

                res.json({ message: 'Bear updated!' });
            });

        });
    })
    
    // delete the bear with this id (accessed at DELETE http://localhost:8080/api/bears/:bear_id)
    .delete(function(req, res) {
        Bear.remove({
            _id: req.params.bear_id
        }, function(err, bear) {
            if (err)
                res.send(err);

            res.json({ message: 'Successfully deleted' });
        });
    });


// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', router);

// START THE SERVER
// ===========================================================================
app.listen(port);
console.log('Magic happens on port ' + port);

@@ -658,20 +658,21 @@
 );%0A%0Avar 
-Bear
+Event
         
@@ -695,20 +695,21 @@
 /models/
-bear
+event
 ');%0A%0A//R
@@ -1207,92 +1207,36 @@
 e: '
-hooray! welcome to our api!' %7D);   %0A%7D);%0A%0A// more routes for our API will happen here
+- Basic API call' %7D);   %0A%7D);
 %0A%0A//
@@ -1363,810 +1363,35 @@
 e('/
-bears')%0A  // create a bear (accessed at POST http://localhost:8080/api/bears)%0A  .post(function(req, res) %7B%0A  %0A    var bear = new Bear();      // create a new instance of the bear model%0A    bear.name = req.body.name;  // set the bears name (comes from the request)%0A    %0A    console.log('INSERT: ' + req.body.name);%0A  %0A    // save the bear and check for errors%0A    bear.save(function(err)%7B%0A      if(err)%0A          res.send(err);%0A      %0A      res.json(%7B message: 'Bear created!'%7D);%0A    %7D);%0A  %7D)%0A%0A  .get(function(req, res) %7B%0A    Bear.find(function(err, bears)%7B%0A      if (err)%0A        res.send(err);%0A      %0A      res.json(bears);%0A    %7D);%0A  %7D);%0A%0A// on routes that end in /bears/:bear_id%0A// ----------------------------------------------------%0Arouter.route('/bears/:bear_id')%0A%0A    // get the bear with that id
+event')%0A  // create a event
  (ac
@@ -1392,34 +1392,35 @@
 nt (accessed at 
-GE
+POS
 T http://localho
@@ -1435,1166 +1435,83 @@
 api/
-bears/:bear_id)%0A    .get(function(req, res) %7B%0A        Bear.findById(req.params.bear_id, function(err, bear) %7B%0A            if (err)%0A                res.send(err);%0A            res.json(bear);%0A        %7D);%0A    %7D)%0A    %0A    // update the bear with this id (accessed at PUT http://localhost:8080/api/bears/:bear_id)%0A    .put(function(req, res) %7B%0A%0A        // use our bear model to find the bear we want%0A        Bear.findById(req.params.bear_id, function(err, bear) %7B%0A%0A            if (err)%0A                res.send(err);%0A%0A            bear.name = req.body.name;  // update the bears info%0A%0A            // save the bear%0A            bear.save(function(err) %7B%0A                if (err)%0A                    res.send(err);%0A%0A                res.json(%7B message: 'Bear updated!' %7D);%0A            %7D);%0A%0A        %7D);%0A    %7D)%0A    %0A    // delete the bear with this id (accessed at DELETE http://localhost:8080/api/bears/:bear_id)%0A    .delete(function(req, res) %7B%0A        Bear.remove(%7B%0A            _id: req.params.bear_id%0A        %7D, function(err, bear) %7B%0A            if (err)%0A                res.send(err);%0A%0A            res.json(%7B message: 'Successfully deleted' %7D);%0A        %7D);%0A    %7D);%0A
+event)%0A  .post(function(req, res) %7B%0A  %7D)%0A%0A  .get(function(req, res) %7B%0A  %7D);
 %0A%0A//

Remove bear route from application