<commit_before>var express = require('express');
var router = express.Router();
var Bookmark = require('../models/bookmark');

/* GET users listing. */
router.get('/', function(req, res, next) {
  if(req.query.category){
    Bookmark.find({category:req.query.category}, function(err, bookmarks){
      if(err){
        return res.send('Error');
      }
      res.send(bookmarks);
    });
  } else {
    Bookmark.find({}, function(err, bookmarks){
      if(err){
        return res.send('Error');
      }
      res.send(bookmarks);
    });
  }

});

router.post('/', function(req, res, next){
  console.log(req.body);
  var bookmark = new Bookmark(req.body); //expect the model structure in the body directly

  bookmark.save(function (err, updatedBookmark) {
    if (err){
      console.log(err);
      res.status(500).send(err);
    } else {
      //res.set('Location', 'http://localhost:3000/bookmarks/' + updatedBookmark.id);
      res.status(201).send('Bookmark created');
    }
    // saved!
  });

});

module.exports = router;
<commit_msg>add get bookmark by id function<commit_after>var express = require('express');
var router = express.Router();
var Bookmark = require('../models/bookmark');


/* GET bookmark by id. */
router.get('/:id', function(req, res, next) {
  Bookmark.findById(req.params.id, function(err, bookmark){
    if(err){
      return res.send('Error');
    }
    res.send(bookmark);
  });

});


/* GET bookmarks listing. */
router.get('/', function(req, res, next) {
  if(req.query.category){
    Bookmark.find({category:req.query.category}, function(err, bookmarks){
      if(err){
        return res.send('Error');
      }
      res.send(bookmarks);
    });
  } else {
    Bookmark.find({}, function(err, bookmarks){
      if(err){
        return res.send('Error');
      }
      res.send(bookmarks);
    });
  }

});

router.post('/', function(req, res, next){
  console.log(req.body);
  var bookmark = new Bookmark(req.body); //expect the model structure in the body directly

  bookmark.schema.pre('save', function (next) {
    if (!this.creation_date) this.creation_date = new Date;
    next();
  });

  bookmark.save(function (err, updatedBookmark) {
    if (err){
      console.log(err);
      res.status(500).send(err);
    } else {
      res.set('Location', 'http://localhost:3000/bookmarks/' + updatedBookmark.id);
      res.status(201).send('Bookmark created');
    }
    // saved!
  });

});

module.exports = router;

{'fraction_non_alphanumeric': 0.18292682926829268, 'fraction_numerical': 0.008130081300813009, 'mean_word_length': 3.0212418300653594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2928647', 'n_tokens_mistral': 821, 'n_tokens_neox': 799, 'n_words': 159}