Skip to content
Permalink
Browse files

Add page size as query param for guide pagination

  • Loading branch information...
SeinopSys committed Jul 18, 2019
1 parent 2afa51f commit c467544f4a282cb2719b6ec3f0edcaf597caa059
Showing with 24 additions and 2 deletions.
  1. +17 −1 app/Controllers/API/AppearancesController.php
  2. +2 −0 app/Controllers/API/UsersController.php
  3. +5 −1 app/CoreUtils.php
@@ -119,6 +119,14 @@ class AppearancesController extends APIController {
* enum={"pony", "eqg"},
* default="pony"
* )
*
* @OA\Schema(
* schema="GuidePageSize",
* type="integer",
* minimum=7,
* maximum=20,
* default=7
* )
*
* @OA\Get(
* path="/api/v1/appearances",
@@ -134,6 +142,12 @@ class AppearancesController extends APIController {
* name="page",
* @OA\Schema(ref="#/components/schemas/PageNumber"),
* description="Which page of results to return"
* ),
* @OA\Parameter(
* in="query",
* name="size",
* @OA\Schema(ref="#/components/schemas/GuidePageSize"),
* description="The number of results to return per page"
* ),
* @OA\Parameter(
* in="query",
@@ -165,7 +179,9 @@ function queryPublic() {
HTTP::statusCode(503);
Response::fail('ELASTIC_DOWN');
}
$appearances_per_page = UserPrefs::get('cg_itemsperpage');
if (isset($_GET['size']) && is_numeric($_GET['size']))
$appearances_per_page = CoreUtils::rangeLimit(intval($_GET['size'], 10), 7, 20);
else $appearances_per_page = 7;
$pagination = new Pagination('', $appearances_per_page);
$searching = !empty($_GET['q']) && $_GET['q'] !== '';
$guide_name = $_GET['guide'] ?? null;
@@ -129,4 +129,6 @@ function me() {
'sessionUpdating' => Auth::$session->updating,
]);
}
// TODO Endpoint for changing user settings
}
@@ -491,7 +491,11 @@ public static function capitalize($str, $all = false){
else return mb_strlen($str) === 1 ? strtoupper($str) : strtoupper($str[0]).mb_substr($str,1);
}
// Turns a file size ini setting value into bytes
public static function rangeLimit(int $value, int $min, int $max){
return min($max, max($min, $value));
}
// Turns a file size ini setting value into bytes
private static function _shortSizeInBytes($size){
$unit = mb_substr($size, -1);
$value = \intval(mb_substr($size, 0, -1), 10);

0 comments on commit c467544

Please sign in to comment.
You can’t perform that action at this time.