Skip to content
Snippets Groups Projects
Commit 633de2da authored by Fawwaz Anugrah Wiradhika Dharmasatya's avatar Fawwaz Anugrah Wiradhika Dharmasatya
Browse files

feat: pagination sudah kelar harusnya

parent ca3ac134
Branches
No related merge requests found
...@@ -10,6 +10,8 @@ use Model\Relations\Subscription; ...@@ -10,6 +10,8 @@ use Model\Relations\Subscription;
use Lib\Service\Api\FetchAPI; use Lib\Service\Api\FetchAPI;
class SubsciberController { class SubsciberController {
const DEFAULT_PAGE = 1;
const DEFAULT_LIMIT = 10;
static function setStatus(IRequest $req, IResponse $res) { static function setStatus(IRequest $req, IResponse $res) {
$subscriber = new Subscription($req->db); $subscriber = new Subscription($req->db);
$transaction = $subscriber->transaction(); $transaction = $subscriber->transaction();
...@@ -140,11 +142,11 @@ class SubsciberController { ...@@ -140,11 +142,11 @@ class SubsciberController {
} }
} }
static function fetchSubscriptions(int $user_id,$db){ static function fetchSubscriptions(int $page,int $limit, int $user_id,$db){
$fetcher = new FetchAPI(getenv("REST_HOST")); $fetcher = new FetchAPI(getenv("REST_HOST"));
$param = [ $param = [
"page"=>1, "page"=>$page,
"limit"=>10 "limit"=>$limit,
]; ];
$rest_key = getenv("REST_KEY"); $rest_key = getenv("REST_KEY");
$headers = [ $headers = [
...@@ -196,7 +198,13 @@ class SubsciberController { ...@@ -196,7 +198,13 @@ class SubsciberController {
static function getPremiumSinger(IRequest $req, IResponse $res){ static function getPremiumSinger(IRequest $req, IResponse $res){
//data ada //data ada
$user_id = $req->auth?$req->auth->user_id:-1; $user_id = $req->auth?$req->auth->user_id:-1;
$data = SubsciberController::fetchSubscriptions($user_id,$req->db); $page = $req->getQuery("page") ?
($req->getQuery("page")>0 ? $req->getQuery("page") : SubsciberController::DEFAULT_PAGE)
: SubsciberController::DEFAULT_PAGE;
$limit = $req->getQuery("limit") ?
($req->getQuery("limit")>0?$req->getQuery("limit"):SubsciberController::DEFAULT_LIMIT)
:SubsciberController::DEFAULT_LIMIT;
$data = SubsciberController::fetchSubscriptions($page,$limit,$user_id,$req->db);
if(!$data){ if(!$data){
// return $res->json([ // return $res->json([
// "status"=>"failed", // "status"=>"failed",
...@@ -208,11 +216,24 @@ class SubsciberController { ...@@ -208,11 +216,24 @@ class SubsciberController {
} }
// $data = json_decode($output,true)["data"]; // $data = json_decode($output,true)["data"];
$page = 1; //fetch max page
$fetcher = new FetchAPI(getenv("REST_HOST"));
$param = [
"page-size"=>$limit,
];
$rest_key = getenv("REST_KEY");
$headers = [
"X-API-KEY"=> $rest_key
];
$output = $fetcher->get("/singers/max-page",$param,$headers);
$total_page = 1; $total_page = 1;
if($output){
$total_page = json_decode($output,true)["data"];
}
return $res->view("Pages/PremiumSinger", [ return $res->view("Pages/PremiumSinger", [
"singers" => $data, "singers" => $data,
"page" => $page, "page" => $page,
"limit"=>$limit,
"next_page" => $page < $total_page ? $page + 1 : null, "next_page" => $page < $total_page ? $page + 1 : null,
"prev_page" => $page > 1 ? $page - 1 : null, "prev_page" => $page > 1 ? $page - 1 : null,
"auth" => $req->auth, "auth" => $req->auth,
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
"/static/css/premium-singer.css", "/static/css/premium-singer.css",
"/static/css/form.css" "/static/css/form.css"
], ],
"scripts"=>[
"/static/js/premium-singer.js"
],
]); ]);
?> ?>
...@@ -29,7 +32,7 @@ ...@@ -29,7 +32,7 @@
foreach($singers as $number=>$singer) { foreach($singers as $number=>$singer) {
?> ?>
<tr> <tr>
<td><?= $number+1 ?></td> <td><?= (10*($page-1))+($number+1) ?></td>
<td><?= $singer["name"] ?></td> <td><?= $singer["name"] ?></td>
<?php if(isset($auth)){ ?> <?php if(isset($auth)){ ?>
<td> <td>
...@@ -58,7 +61,7 @@ ...@@ -58,7 +61,7 @@
<?php <?php
$this->component("Component/Pagination", [ $this->component("Component/Pagination", [
"page_number" => $page, "page_number" => $page,
"next_page" => isset($next_page) && !is_null($next_page) ? "/admin/users/?page=$next_page": null, "next_page" => isset($next_page) && !is_null($next_page) ? "/premium?page=$next_page&limit=$limit": null,
"prev_page" => isset($prev_page) && !is_null($prev_page) ? "/admin/users/?page=$prev_page": null, "prev_page" => isset($prev_page) && !is_null($prev_page) ? "/premium?page=$prev_page&limit=$limit": null,
]) ])
?> ?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment