Skip to content

Commit

Permalink
Add page size as query param for guide pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
SeinopSys committed Jul 20, 2019
1 parent 2afa51f commit c467544
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
18 changes: 17 additions & 1 deletion app/Controllers/API/AppearancesController.php
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions app/Controllers/API/UsersController.php
Expand Up @@ -129,4 +129,6 @@ function me() {
'sessionUpdating' => Auth::$session->updating,
]);
}

// TODO Endpoint for changing user settings
}
6 changes: 5 additions & 1 deletion app/CoreUtils.php
Expand Up @@ -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);
Expand Down

0 comments on commit c467544

Please sign in to comment.