<commit_before><?php

use Slim\Http\Request;
use Slim\Http\Response;

$container = $app->getContainer();

$container['database'] = function () use ($app) {
  $db_url = $_ENV['DATABASE_URL'];
  $db_user = $_ENV['DATABASE_USER'];
  $db_pwd = $_ENV['DATABASE_PWD'];

  $pdo = new \Slim\PDO\Database(getenv('DATABASE_URL'), getenv('DATABASE_USER'), getenv('DATABASE_PWD'));
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

  return $pdo;
};

$app->get('/', function (Request $request, Response $response, array $args) {
  return $this->renderer->render($response, 'index.phtml', $args);
});

$app->get('/products', function (Request $request, $response, $args) {
  $offset = intval($request->getQueryParam('offset', $default = '0'));
  $limit = intval($request->getQueryParam('limit', $default = '10'));
  $order = $request->getQueryParam('order', $default = 'asc'); # asc / desc
  $order_by = $request->getQueryParam('order_by', $default = 'id'); # id / price

  $stmt = $this->get('database')
          ->select()
          ->from('product_listing')
          ->limit($limit, $offset)
          ->execute();

  $result = array(
    'data' => $stmt->fetchAll(),
    'next_page' => ('/products?offset=' . ($offset + $limit) . "&limit=" . $limit)
  );

  return $response->withJson($result);
});<commit_msg>Support for ordering on backend<commit_after><?php

use Slim\Http\Request;
use Slim\Http\Response;

$container = $app->getContainer();

$container['database'] = function () use ($app) {
  $db_url = $_ENV['DATABASE_URL'];
  $db_user = $_ENV['DATABASE_USER'];
  $db_pwd = $_ENV['DATABASE_PWD'];

  $pdo = new \Slim\PDO\Database(getenv('DATABASE_URL'), getenv('DATABASE_USER'), getenv('DATABASE_PWD'));
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

  return $pdo;
};

$app->get('/', function (Request $request, Response $response, array $args) {
  return $this->renderer->render($response, 'index.phtml', $args);
});

$app->get('/products', function (Request $request, $response, $args) {
  $offset = intval($request->getQueryParam('offset', $default = '0'));
  $limit = intval($request->getQueryParam('limit', $default = '10'));
  $order = $request->getQueryParam('order', $default = 'asc'); # asc / desc
  $order_by = $request->getQueryParam('order_by', $default = 'id'); # id / price

  $stmt = $this->get('database')
          ->select()
          ->from('product_listing')
          ->limit($limit, $offset)
          ->orderBy($order_by, $order)
          ->execute();

  $result = array(
    'data' => $stmt->fetchAll(),
    'next_page' => ('/products?offset=' . ($offset + $limit) . "&limit=" . $limit . "&order_by=" . $order_by . "&order=" . $order)
  );

  return $response->withJson($result);
});
{'fraction_non_alphanumeric': 0.2166608330416521, 'fraction_numerical': 0.0021001050052502626, 'mean_word_length': 4.560311284046692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '4689162', 'n_tokens_mistral': 1006, 'n_tokens_neox': 995, 'n_words': 180}