mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
refactorings
This commit is contained in:
parent
714d4cb490
commit
10d25cc022
@ -381,7 +381,7 @@ class Anime extends JikanApiSearchableModel
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
"field" => "_text_match(buckets:" . App::make("jikan-config")->maxResultsPerPage() . ")",
|
"field" => "_text_match(buckets:" . max_results_per_page() . ")",
|
||||||
"direction" => "desc"
|
"direction" => "desc"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -8,7 +8,7 @@ trait ResolvesPaginatorParams
|
|||||||
{
|
{
|
||||||
private function getPaginatorParams(?int $limit = null, ?int $page = null): array
|
private function getPaginatorParams(?int $limit = null, ?int $page = null): array
|
||||||
{
|
{
|
||||||
$default_max_results_per_page = App::make("jikan-config")->maxResultsPerPage();
|
$default_max_results_per_page = max_results_per_page();
|
||||||
$limit = $limit ?? $default_max_results_per_page;
|
$limit = $limit ?? $default_max_results_per_page;
|
||||||
$page = $page ?? 1;
|
$page = $page ?? 1;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ trait PreparesData
|
|||||||
// let's always set the limit parameter to the globally configured default value
|
// let's always set the limit parameter to the globally configured default value
|
||||||
if (property_exists(static::class, "limit") && !$properties->has("limit")) {
|
if (property_exists(static::class, "limit") && !$properties->has("limit")) {
|
||||||
/** @noinspection PhpUndefinedFieldInspection */
|
/** @noinspection PhpUndefinedFieldInspection */
|
||||||
$properties->put("limit", App::make("jikan-config")->maxResultsPerPage(
|
$properties->put("limit", max_results_per_page(
|
||||||
property_exists(static::class, "defaultLimit") ? static::$defaultLimit : null));
|
property_exists(static::class, "defaultLimit") ? static::$defaultLimit : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ final class MaxResultsPerPageRule implements Rule
|
|||||||
$value = intval($value);
|
$value = intval($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value > $this->maxResultsPerPage()) {
|
if ($value > max_results_per_page()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +37,7 @@ final class MaxResultsPerPageRule implements Rule
|
|||||||
|
|
||||||
public function message(): array|string
|
public function message(): array|string
|
||||||
{
|
{
|
||||||
return "Value {$this->value} is higher than the configured '{$this->maxResultsPerPage()}' max value.";
|
$mrpp = max_results_per_page();
|
||||||
}
|
return "Value {$this->value} is higher than the configured '$mrpp' max value.";
|
||||||
|
|
||||||
private function maxResultsPerPage(): int
|
|
||||||
{
|
|
||||||
return (int) App::make("jikan-config")->maxResultsPerPage($this->fallbackLimit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,3 +54,10 @@ if (!function_exists('to_boolean')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('max_results_per_page')) {
|
||||||
|
function max_results_per_page(?int $fallbackLimit = null): int
|
||||||
|
{
|
||||||
|
return app()->make("jikan-config")->maxResultsPerPage($fallbackLimit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user