<commit_before>var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
//获取Goods模型
var Goods = require('../models/goods');

//链接数据库
mongoose.connect('mongodb://127.0.0.1:27017/mall',{useMongoClient:true});
//监听是否链接成功
mongoose.connection.on('connected', function (){
    console.log('MongoDB connected success.')
})
mongoose.connection.on('error', function (){
    console.log('MongoDB connected fail.')
})
mongoose.connection.on('disconnected', function (){
    console.log('MongoDB connected disconnected.')
})



/* GET users listing. */
router.get('/', function(req, res, next) {
    Goods.find({},function (err,doc){
        if(err){
            res.json({
                status:"500",
                msg:"错误"
            })
        }else{
            res.json({
                status:"200",
                result:{
                    data: doc
                },
                pagination: {
                    count: doc.length
                }                
            })
        }
    })
//   res.send('goods');
});

module.exports = router;<commit_msg>goods接口GET<commit_after>var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
//获取Goods模型
var Goods = require('../models/goods');

//链接数据库
mongoose.connect('mongodb://127.0.0.1:27017/mall',{useMongoClient:true});
//监听是否链接成功
mongoose.connection.on('connected', function (){
    console.log('MongoDB connected success.')
})
mongoose.connection.on('error', function (){
    console.log('MongoDB connected fail.')
})
mongoose.connection.on('disconnected', function (){
    console.log('MongoDB connected disconnected.')
})



/* GET users listing. */
router.get('/', function(req, res, next) {
    let query = req.query;
    let originUrl = req.originUrl;
    //页数
    let page = parseInt(req.param('page'))||1;
    //数量
    let length =parseInt(req.param('length'))||8;
    //offset
    let offset= (page-1)*length;
    //排序
    let sort = parseInt(req.param('sort'))||1;
    let param = {};
    //limit 限制条数
    //skip 跳过？条

    Goods.find(param,function (err,doc){
        if(err){
            res.json({
                status:"500",
                msg:"错误"
            })
        }else{
            var total = doc.length;
            getData(total);
        }
    })     

    function getData(total){
        let GoodsModel = Goods.find(param).limit(length).skip(offset);
        GoodsModel.sort({salePrice:sort});
        GoodsModel.exec(function (err,doc){
            if(err){
                res.json({
                    status:"500",
                    msg:"错误"
                })
            }else{
                res.json({
                    status:"200",
                    result:{
                        data: doc
                    },
                    pagination: {
                        count: doc.length,
                        offset:offset,
                        total:total
                    }                
                })
            }
        })

    }
    
//   res.send('goods');
});

module.exports = router;
{'fraction_non_alphanumeric': 0.15502882767456758, 'fraction_numerical': 0.01313260730301089, 'mean_word_length': 1.6421319796954315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4529188', 'n_tokens_mistral': 969, 'n_tokens_neox': 955, 'n_words': 158}