mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
magazines: add detailed pagination + update docs
This commit is contained in:
parent
d03ab2b6b1
commit
3c12739067
@ -11,9 +11,6 @@ use Illuminate\Http\Request;
|
||||
|
||||
class MagazineController extends Controller
|
||||
{
|
||||
|
||||
const MAX_RESULTS_PER_PAGE = 25;
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/magazines",
|
||||
@ -21,6 +18,32 @@ class MagazineController extends Controller
|
||||
* tags={"magazines"},
|
||||
*
|
||||
* @OA\Parameter(ref="#/components/parameters/page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/limit"),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="q",
|
||||
* in="query",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="order_by",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/magazines_query_orderby")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="sort",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/search_query_sort")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="letter",
|
||||
* in="query",
|
||||
* description="Return entries starting with the given letter",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
@ -36,21 +59,21 @@ class MagazineController extends Controller
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function main(Request $request)
|
||||
public function main(Request $request): MagazineCollection
|
||||
{
|
||||
$maxResultsPerPage = (int) env('MAX_RESULTS_PER_PAGE', 25);
|
||||
|
||||
$page = $request->get('page') ?? 1;
|
||||
$limit = $request->get('limit') ?? self::MAX_RESULTS_PER_PAGE;
|
||||
$limit = $request->get('limit') ?? $maxResultsPerPage;
|
||||
|
||||
if (!empty($limit)) {
|
||||
$limit = (int) $limit;
|
||||
$limit = (int) $limit;
|
||||
|
||||
if ($limit <= 0) {
|
||||
$limit = 1;
|
||||
}
|
||||
if ($limit <= 0) {
|
||||
$limit = 1;
|
||||
}
|
||||
|
||||
if ($limit > self::MAX_RESULTS_PER_PAGE) {
|
||||
$limit = self::MAX_RESULTS_PER_PAGE;
|
||||
}
|
||||
if ($limit > $maxResultsPerPage) {
|
||||
$limit = $maxResultsPerPage;
|
||||
}
|
||||
|
||||
$results = SearchQueryBuilderMagazine::query(
|
||||
|
@ -24,6 +24,31 @@ class ProducerController extends Controller
|
||||
* @OA\Parameter(ref="#/components/parameters/page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/limit"),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="q",
|
||||
* in="query",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="order_by",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/producers_query_orderby")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="sort",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/search_query_sort")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="letter",
|
||||
* in="query",
|
||||
* description="Return entries starting with the given letter",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="Returns producers collection",
|
||||
|
@ -26,34 +26,6 @@ class MagazineCollection extends ResourceCollection
|
||||
* schema="magazines",
|
||||
* description="Magazine Collection Resource",
|
||||
*
|
||||
* @OA\Parameter(ref="#/components/parameters/page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/limit"),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="q",
|
||||
* in="query",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="order_by",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/magazines_query_orderby")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="sort",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/search_query_sort")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="letter",
|
||||
* in="query",
|
||||
* description="Return entries starting with the given letter",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* allOf={
|
||||
* @OA\Schema(ref="#/components/schemas/pagination"),
|
||||
* @OA\Schema(
|
||||
@ -76,7 +48,13 @@ class MagazineCollection extends ResourceCollection
|
||||
{
|
||||
$this->pagination = [
|
||||
'last_visible_page' => $resource->lastPage(),
|
||||
'has_next_page' => $resource->hasMorePages()
|
||||
'has_next_page' => $resource->hasMorePages(),
|
||||
'current_page' => $resource->currentPage(),
|
||||
'items' => [
|
||||
'count' => $resource->count(),
|
||||
'total' => $resource->total(),
|
||||
'per_page' => $resource->perPage(),
|
||||
],
|
||||
];
|
||||
|
||||
$this->collection = $resource->getCollection();
|
||||
@ -104,4 +82,4 @@ class MagazineCollection extends ResourceCollection
|
||||
unset($jsonResponse['links'],$jsonResponse['meta']);
|
||||
$response->setContent(json_encode($jsonResponse));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,34 +26,6 @@ class ProducerCollection extends ResourceCollection
|
||||
* schema="producers",
|
||||
* description="Producer Collection Resource",
|
||||
*
|
||||
* @OA\Parameter(ref="#/components/parameters/page"),
|
||||
* @OA\Parameter(ref="#/components/parameters/limit"),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="q",
|
||||
* in="query",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="order_by",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/producers_query_orderby")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="sort",
|
||||
* in="query",
|
||||
* @OA\Schema(ref="#/components/schemas/search_query_sort")
|
||||
* ),
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="letter",
|
||||
* in="query",
|
||||
* description="Return entries starting with the given letter",
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
*
|
||||
* allOf={
|
||||
* @OA\Schema(ref="#/components/schemas/pagination"),
|
||||
* @OA\Schema(
|
||||
|
@ -1166,6 +1166,38 @@
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/components/parameters/page"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/limit"
|
||||
},
|
||||
{
|
||||
"name": "q",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "order_by",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/magazines_query_orderby"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sort",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/search_query_sort"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "letter",
|
||||
"in": "query",
|
||||
"description": "Return entries starting with the given letter",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@ -1875,6 +1907,35 @@
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/limit"
|
||||
},
|
||||
{
|
||||
"name": "q",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "order_by",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/producers_query_orderby"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sort",
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/search_query_sort"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "letter",
|
||||
"in": "query",
|
||||
"description": "Return entries starting with the given letter",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user