magazines: add detailed pagination + update docs

This commit is contained in:
Irfan 2022-07-27 22:10:10 +05:00
parent d03ab2b6b1
commit 3c12739067
5 changed files with 130 additions and 71 deletions

View File

@ -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
{
$page = $request->get('page') ?? 1;
$limit = $request->get('limit') ?? self::MAX_RESULTS_PER_PAGE;
$maxResultsPerPage = (int) env('MAX_RESULTS_PER_PAGE', 25);
$page = $request->get('page') ?? 1;
$limit = $request->get('limit') ?? $maxResultsPerPage;
if (!empty($limit)) {
$limit = (int) $limit;
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(

View File

@ -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",

View File

@ -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();

View File

@ -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(

View File

@ -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": {