'use strict';

module.exports = function(app) {
    var users = require('../../app/controllers/users');
    var products = require('../../app/controllers/products');

    // Products Routes
    app.route('/products')
        .get(products.list)
        .post(users.requiresLogin, products.create);

    app.route('/products/:productId')
        .get(products.read)
        .put(users.requiresLogin, products.hasAuthorization, products.update)
        .delete(users.requiresLogin, products.hasAuthorization, products.delete);
    //upvoting a product
    app.route('/products/:productId/upvote')
        .post(users.requiresLogin, products.upVote);
    //downvoting a product
    app.route('/products/:productId/downvote')
        .post(users.requiresLogin, products.downVote);
    //Product Comments
    app.route('/products/:productId/comments')
        .get(products.listProductComments)
        .post(users.requiresLogin, products.comment);

    // Finish by binding the Product middleware
    app.param('productId', products.productByID);
};