<commit_before>'use strict';

var _ = require('lodash');

var Router = require('koa-router'),
  body = require('koa-better-body');

module.exports = function BikeshedsController (helpers) {
  var middleware = helpers.middleware,
    auth = middleware.auth(),
    loadUser = middleware.loadUser,
    loadBikeshed = middleware.loadResource('Bikeshed');

  var jsonBody = body(),
    multipartBody = body({multipart: true});

  var bikeshedRoutes = new Router()

    // public
    .get('/bikesheds', index)
    .get('/bikesheds/:bikeshed', loadBikeshed, get)
    .get('/bikesheds/:bikeshed/votes', loadBikeshed, score)

    // private
    .post('/bikesheds', auth, loadUser, jsonBody, create)
    .del('/bikesheds/:bikeshed', auth, loadUser, loadBikeshed, destroy)
    .post('/bikesheds/:bikeshed', auth, loadUser, loadBikeshed, multipartBody, upload)
    .post('/bikesheds/:bikeshed/votes', auth, loadUser, loadBikeshed, jsonBody, vote);

  return bikeshedRoutes.middleware();
};

/**
 * GET /bikesheds
 * Public
 * Parameters: sortBy, direction, page, per
 *  per: default 12, minimum 1, maximum 96
 *  page: default 1, minimum 1
 *  sortBy: default id
 *  direction: default desc
 */
function* index () {
  var Bikeshed = this.models.Bikeshed,
    query = this.request.query,
    page = _.parseInt(query.page),
    per = _.parseInt(query.per),
    sortBy = query.sortBy,
    direction = (query.direction || '').toLowerCase();

  page = page >= 1 ? page : 1;
  per = per >= 1 ? (per < 96 ? per : 96) : 12;
  direction = _.contains(['asc', 'desc'], direction) ? direction : 'desc';
  sortBy = _.contains(_.keys(Bikeshed.tableAttributes), sortBy) ? sortBy : 'id';

  var result = yield Bikeshed.findAndCountAll({
    where: {published: true},
    limit: per,
    offset: (page - 1) * per,
    order: sortBy + ' ' + direction
  });

  this.body = {
    bikesheds: result.rows,
    count: result.count,
    page: page,
    pages: Math.ceil(result.count / per),
    per: per,
    sortBy: sortBy,
    direction: direction
  };<commit_msg>update bikeshed sorting to use caps<commit_after>'use strict';

var _ = require('lodash');

var Router = require('koa-router'),
  body = require('koa-better-body');

module.exports = function BikeshedsController (helpers) {
  var middleware = helpers.middleware,
    auth = middleware.auth(),
    loadUser = middleware.loadUser,
    loadBikeshed = middleware.loadResource('Bikeshed');

  var jsonBody = body(),
    multipartBody = body({multipart: true});

  var bikeshedRoutes = new Router()

    // public
    .get('/bikesheds', index)
    .get('/bikesheds/:bikeshed', loadBikeshed, get)
    .get('/bikesheds/:bikeshed/votes', loadBikeshed, score)

    // private
    .post('/bikesheds', auth, loadUser, jsonBody, create)
    .del('/bikesheds/:bikeshed', auth, loadUser, loadBikeshed, destroy)
    .post('/bikesheds/:bikeshed', auth, loadUser, loadBikeshed, multipartBody, upload)
    .post('/bikesheds/:bikeshed/votes', auth, loadUser, loadBikeshed, jsonBody, vote);

  return bikeshedRoutes.middleware();
};

/**
 * GET /bikesheds
 * Public
 * Parameters: sortBy, direction, page, per
 *  per: default 12, minimum 1, maximum 96
 *  page: default 1, minimum 1
 *  sortBy: default id
 *  direction: default desc
 */
function* index () {
  var Bikeshed = this.models.Bikeshed,
    query = this.request.query,
    page = _.parseInt(query.page),
    per = _.parseInt(query.per),
    sortBy = query.sortBy,
    direction = (query.direction || '').toUpperCase();

  page = page >= 1 ? page : 1;
  per = per >= 1 ? (per < 96 ? per : 96) : 12;
  direction = _.contains(['ASC', 'DESC'], direction) ? direction : 'DESC';
  sortBy = _.contains(_.keys(Bikeshed.tableAttributes), sortBy) ? sortBy : 'id';

  var result = yield Bikeshed.findAndCountAll({
    where: {published: true},
    limit: per,
    offset: (page - 1) * per,
    order: [[sortBy, direction]]
  });

  this.body = {
    bikesheds: result.rows,
    count: result.count,
    page: page,
    pages: Math.ceil(result.count / per),
    per: per,
    sortBy: sortBy,
    direction: direction
  };
{'fraction_non_alphanumeric': 0.15363881401617252, 'fraction_numerical': 0.008331291350159274, 'mean_word_length': 3.4857142857142858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070855', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1379, 'n_words': 333}