<commit_before>module.exports = function () {
    var express = require('express');
    var unirest = require('unirest');
    var app = express();

    var Game = require('../../models/game');

    // Create a game (accessed at POST http://localhost:8080/api/games)
    app
        // -----------------------------------------------------------------------------------
        // --                                       POST                                    --
        // -----------------------------------------------------------------------------------

        // Description : Add a new game
        // URL: http://localhost:8080/api/games
        // Param :
        //          - name
        .post('/games', function (req, res) {

            var game = new Game();      // create a new instance of the Game model
            game.name = req.body.name;  // set the games name (comes from the request)

            // save the game and check for errors
            game.save(function (err) {
                if (err)
                    res.send(err.message);

                console.log('Game ' + game.name + ' added !');
                res.json({message: 'Game added !', game: game});
            });
        })

        // -----------------------------------------------------------------------------------
        // --                                       GET                                     --
        // -----------------------------------------------------------------------------------

        // Description : Get all the games
        // URL : http://localhost:8080/api/games
        .get('/games', function (req, res) {
            Game.find(function (err, games) {
                if (err)
                    res.send(err);

                Game.count({}, function (err, count) {
                    if (err)
                        res.send(err);
                    console.log(count + ' game(s) founded !');
                    res.json({message: count + ' game(s) founded !', count: count, games: games});
                })
            });
        })

        // Description : Get games by a name
        // URL : http://localhost:8080/api/games/by/name/:name
        .get('/games/by/name/:game_name', function (req, res) {
            Game.find({name: req.params.game_name}, function (err, games) {
                if (err)
                    res.send(err);

                Game.count({name: req.params.game_name}, function (err, count) {
                    if (err)
                        res.send(err);
                    console.log(count + ' game(s) founded !');
                    res.json({message: count + ' game(s) founded !', count: count, games: games});
                });
            });
        })

        // Description : Get a game by an id
        // URL : http://localhost:8080/api/games/by/:id
        .get('/games/by/id/:game_id', function (req, res) {
            Game.findById(req.params.game_id, function (err, game) {
                if (err)
                    res.send(err);
                console.log('Searching for game id ' + req.params.game_id + ' : ' + game.name);
                res.json({message: 'Game founded !', game: game});
            });
        })

        // -----------------------------------------------------------------------------------
        // --                                       PUT                                     --
        // -----------------------------------------------------------------------------------

        // Description : Update a game with an id
        // URL : http://localhost:8080/api/games/:game_id
        // Param :
        //          - id
        // Body :
        //          - Game Object
        .put('/games/:game_id', function (req, res) {
            // Use our game model to find the game we want
            Game.findById(req.params.game_id, function (err, game) {
                if (err)
                    res.send(err);

                // Update the games info
                game.name = req.body.name;
                game.overview = req.body.overview;
                game.editors = req.body.editors;
                game.developers = req.body.developers;
                game.genres = req.body.genres;
                game.platforms = req.body.platforms;
                game.releaseDate = req.body.releaseDate;
                game.updateDate = new Date();

                if (req.body.metacritic) {
                    game.metacritic.score = req.body.metacritic.score;
                    game.metacritic.url = req.body.metacritic.url;
                }

                if (req.body.media) {
                    if (req.body.media.boxArt) {
                        game.media.boxArt.front = req.body.media.boxArt.front;
                        game.media.boxArt.rear = req.body.media.boxArt.rear;
                    }
                    game.media.thumbnails = req.body.media.thumbnails;<commit_msg>Add pagination params for games search.<commit_after>module.exports = function () {
    var express = require('express');
    var unirest = require('unirest');
    var app = express();

    var Game = require('../../models/game');

    // Create a game (accessed at POST http://localhost:8080/api/games)
    app
        // -----------------------------------------------------------------------------------
        // --                                       POST                                    --
        // -----------------------------------------------------------------------------------

        // Description : Add a new game
        // URL: http://localhost:8080/api/games
        // Form params :
        //          - name
        .post('/games', function (req, res) {

            var game = new Game();      // create a new instance of the Game model
            game.name = req.body.name;  // set the games name (comes from the request)

            // save the game and check for errors
            game.save(function (err) {
                if (err)
                    res.send(err.message);

                console.log('Game ' + game.name + ' added !');
                res.json({message: 'Game added !', game: game});
            });
        })

        // -----------------------------------------------------------------------------------
        // --                                       GET                                     --
        // -----------------------------------------------------------------------------------

        // Description : Get all the games, come with pagination params
        // URL : http://localhost:8080/api/games/?skip=:skip&limit=:limit
        // URL params :
        //          - skip
        //          - limit
        .get('/games', function (req, res) {

            var skip = req.param('skip');
            var limit = req.param('limit');

            console.log("-- Searching games with skip '" + skip + "' and limit '" + limit + "'...");

            Game.find()
                .skip(skip)
                .limit(limit)
                .exec(function (err, games) {
                    if (err)
                        res.send(err);

                    var count = games.length;
                    console.log('-- ' + count + ' game(s) founded !');

                    res.json({
                        message: count + ' game(s) founded !',
                        skip: skip,
                        limit: limit,
                        games: games
                    });
                });
        })


        // Description : Get games by a name
        // URL : http://localhost:8080/api/games/by/name/:name
        .get('/games/by/name/:game_name', function (req, res) {
            Game.find({name: req.params.game_name}, function (err, games) {
                if (err)
                    res.send(err);

                Game.count({name: req.params.game_name}, function (err, count) {
                    if (err)
                        res.send(err);
                    console.log(count + ' game(s) founded !');
                    res.json({message: count + ' game(s) founded !', count: count, games: games});
                });
            });
        })

        // Description : Get a game by an id
        // URL : http://localhost:8080/api/games/by/:id
        .get('/games/by/id/:game_id', function (req, res) {
            Game.findById(req.params.game_id, function (err, game) {
                if (err)
                    res.send(err);
                console.log('Searching for game id ' + req.params.game_id + ' : ' + game.name);
                res.json({message: 'Game founded !', game: game});
            });
        })

        // -----------------------------------------------------------------------------------
        // --                                       PUT                                     --
        // -----------------------------------------------------------------------------------

        // Description : Update a game with an id
        // URL : http://localhost:8080/api/games/:game_id
        // Param :
        //          - id
        // Form params :
        //          - Game Object
        .put('/games/:game_id', function (req, res) {
            // Use our game model to find the game we want
            Game.findById(req.params.game_id, function (err, game) {
                if (err)
                    res.send(err);

                // Update the games info
                game.name = req.body.name;
                game.overview = req.body.overview;
                game.editors = req.body.editors;
                game.developers = req.body.developers;
                game.genres = req.body.genres;
                game.platforms = req.body.platforms;
                game.releaseDate = req.body.releaseDate;
                game.updateDate = new Date();

                if (req.body.metacritic) {
                    game.metacritic.score = req.body.metacritic.score;
                    game.metacritic.url = req.body.metacritic.url;
                }

                if (req.body.media) {
                    if (req.body.media.boxArt) {
                        game.media.boxArt.front = req.body.media.boxArt.front;
                        game.media.boxArt.rear = req.body.media.boxArt.rear;
                    }
                    game.media.thumbnails = req.body.media.thumbnails;
{'fraction_non_alphanumeric': 0.2118042226487524, 'fraction_numerical': 0.004606525911708253, 'mean_word_length': 0.8658907788719785, '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': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3061982', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2398, 'n_words': 546}