<commit_before>/* jslint node: true */
/* jshint esversion: 6 */
'use strict';
var express  = require('express');
var app = express();
var router = express.Router();
var mongoose = require('mongoose');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');

/**
 * Class definition for httpServer
 * @constructor
 * TODO finish commenting
 */
class HttpServer {

  constructor(settings){
    this.url = settings.url;
    this.path = settings.path;
  }

  /**
   * Prepare and start httpServer app
   * TODO finish commenting
   */
  run() {
    var self = this;
    mongoose.connect(self.url);     // connect to mongoDB database on modulus.io

    app.use(express.static(self.path + '/public'));               // set the static files location /public/img will be /img for users
    app.use(morgan('dev'));                                         // log every request to the console
    app.use(bodyParser.urlencoded({'extended':'true'}));            // parse application/x-www-form-urlencoded
    app.use(bodyParser.json());                                     // parse application/json
    app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
    app.use(methodOverride());

    self.defineAPI();
    self.defineRoute();
    /**
     * Start App and listen on given port
     */
    app.listen(8080, function(){
      console.log("FatCatsJS HTTP listening on port 8080");
    });

  }

  defineAPI() {
    var FatCats = mongoose.model('feeding', {datetime : {type: Date, required: true}});

    //GET
    app.get('/api/feedings', function(req, res){
      FatCats.find().sort({_id:-1}).exec(function(err, feedings) {
        if (err) {
          res.send(err);
        }
        res.json(feedings);
      });
    });

    //POST
    app.post('/api/feedings', function(req, res) {
      FatCats.create({
        datetime : req.body.text,
        type : req.body.text,
        amount : req.body.text
      }, function(err, feeding) {
        if (err) {
          res.send(err);
        }
        FatCats.find(function(err, feedings) {
          if (err){
            res.send(err);
          }
          res.json(feedings);
        });
      });
    });

    //DELETE
    app.delete('/api/feedings/:feeding_id', function(req, res){<commit_msg>Added api get for catfood mongo collection<commit_after>/* jslint node: true */
/* jshint esversion: 6 */
'use strict';
var express  = require('express');
var app = express();
var router = express.Router();
var mongoose = require('mongoose');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');

/**
 * Class definition for httpServer
 * @constructor
 * TODO finish commenting
 */
class HttpServer {

  constructor(settings){
    this.url = settings.url;
    this.path = settings.path;
  }

  /**
   * Prepare and start httpServer app
   * TODO finish commenting
   */
  run() {
    var self = this;
    mongoose.connect(self.url);

    app.use(express.static(self.path + '/public'));               // set the static files location
    app.use(morgan('dev'));                                         // log every request to the console
    app.use(bodyParser.urlencoded({'extended':'true'}));            // parse application/x-www-form-urlencoded
    app.use(bodyParser.json());                                     // parse application/json
    app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
    app.use(methodOverride());

    self.defineAPI();
    self.defineRoute();
    /**
     * Start App and listen on given port
     */
    app.listen(8080, function(){
      console.log("FatCatsJS HTTP listening on port 8080");
    });

  }

  defineAPI() {
    var FatCats = mongoose.model('feeding', {
      datetime : {type: Date, required: true}
    },'feedings');

    var CatFood = mongoose.model('catfood', {
      brand : {type : String},
      name : {type : String},
      consistency : {type : String},
      kcal : {type : Number},
      measurement : {type : String}
    }, 'catfood');
    //GET
    app.get('/api/feedings', function(req, res){
      FatCats.find().sort({"datetime":-1}).exec(function(err, feedings) {
        if (err) {
          res.send(err);
        }
        res.json(feedings);
      });
    });
    app.get('/api/catfood', function(req, res){
      CatFood.find(function(err, catfood) {
        if (err) {
          res.send(err);
        }
        res.json(catfood);
      });
    });

    //POST
    app.post('/api/feedings', function(req, res) {
      FatCats.create({
        datetime : req.body.text,
        type : req.body.text,
        amount : req.body.text
      }, function(err, feeding) {
        if (err) {
          res.send(err);
        }
        FatCats.find(function(err, feedings) {
          if (err){
            res.send(err);
          }
          res.json(feedings);
        });
      });
    });

    //DELETE
    app.delete('/api/feedings/:feeding_id', function(req, res){
{'fraction_non_alphanumeric': 0.15491306895878101, 'fraction_numerical': 0.003907013088493847, 'mean_word_length': 2.170278637770898, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5068422', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1525, 'n_words': 342}