var auth = require('../../lib/auth');
var db = require('../../db');
var user = require('../../lib/user');


module.exports = function(server) {
    // Sample usage:
    // % curl -X POST 'http://localhost:5000/user/purchase' -d '_user=ssatoken&game=9'
    server.post({
        url: '/user/purchase',
        swagger: {
            nickname: 'purchase',
            notes: 'Record that a user has purchased this game',
            summary: 'Purchase game'
        },
        validation: {
            _user: {
                description: 'User (ID or username slug)',
                isRequired: true
            },
            game: {
                description: 'Game (ID or slug)',
                isRequired: true
            }
        }
    }, user.userIDView(function(id, client, done, req, res) {
        var POST = req.params;

        // TODO: Accept ID *or* slug.
        var game = POST.game;
        if (!game) {
            res.json(403, {error: 'bad_game'});
            return;
        }

        client.sadd('gamesPurchased:' + id, game, function(err) {
            done();
            if (err) {
                res.json(500, {error: 'internal_db_error'});
                return;
            }
            res.json({success: true});
        });
    }));
};

@@ -133,24 +133,826 @@
 n(server) %7B%0A
+    // Sample usage:%0A    // %25 curl 'http://localhost:5000/user/purchase?id=0'%0A    server.get(%7B%0A        url: '/user/purchase',%0A        swagger: %7B%0A            nickname: 'get-purchase',%0A            notes: 'Get the list of user purchases',%0A            summary: 'Purchase history'%0A        %7D,%0A        validation: %7B%0A            id: %7B%0A                description: 'user id',%0A                isRequired: true%0A            %7D%0A        %7D%0A    %7D, db.redisView(function(client, done, req, res, wrap)%7B%0A        var GET = req.params;%0A        var id = GET.id;%0A%0A        client.smembers('gamesPurchased:' + id, function(err, resp) %7B%0A            done();%0A            if (err) %7B%0A                res.json(500, %7Berror: 'internal_db_error'%7D);%0A                return;%0A            %7D%0A            res.json(resp);%0A        %7D);%0A    %7D));%0A%0A
     // Sampl
@@ -1047,16 +1047,16 @@
 game=9'%0A
-
     serv
@@ -1338,36 +1338,28 @@
 on: 
-'User (ID or username slug)'
+%22A user's SSA token%22
 ,%0A  

add get user purchase api endpoint