diff --git a/src/components/history/History.php b/src/components/history/History.php index 2558a59b5d66b1aa3ace3afde44a7f9e9e1141a6..cced51fb43ea036bd130c5307c2d7de9f204f9d4 100644 --- a/src/components/history/History.php +++ b/src/components/history/History.php @@ -22,21 +22,19 @@ <?php include_once(dirname(__DIR__) . "/template/HistoryCard.php"); - // TODO : fetch data from REST - $histories = [ - ['courierName' => "jamal", 'price' => 100, 'rating' => 4, 'historyId' => 1], - ['courierName' => "rusdi", 'price' => 69, 'rating' => 0, 'historyId' => 2], - ['courierName' => "Ukin", 'price' => 420, 'rating' => 3, 'historyId' => 3], - ]; + $histories = $this->data; ?> <section class="articles"> <?php + // var_dump($histories); + $index = 1; foreach ($histories as $history) { history_card_template( - $history['courierName'], - $history['price'], + "Pesanan" . $index, + "Penerima: ".$history['nama_penerima'], $history['rating'], - $history['historyId']); + $history['id']); + $index++; } ?> </section> diff --git a/src/controller/history/HistoryController.php b/src/controller/history/HistoryController.php index 0b88076dd295fed0a706f404300c4117c70ba304..db2d189a129d69bae3a0d663354a3e3967d30fb8 100644 --- a/src/controller/history/HistoryController.php +++ b/src/controller/history/HistoryController.php @@ -1,7 +1,17 @@ <?php +require_once __DIR__ . '/../../rest/Rest.php'; class HistoryController extends Controller{ public function index() { - $this->render(); + $userId = $_SESSION['user_id']; + Rest::setEndpoint('history/penerima/'.$userId); + Rest::setOption('GET', null); + + $History = Rest::call(); + + + $data = json_decode($History, true); + // var_dump($data); + $this->render($data); } } \ No newline at end of file diff --git a/src/rest/Rest.php b/src/rest/Rest.php new file mode 100644 index 0000000000000000000000000000000000000000..5a8304d74574ed8c485b432c8db919be262a577f --- /dev/null +++ b/src/rest/Rest.php @@ -0,0 +1,43 @@ +<?php + +class Rest { + public static $apiEndpoint; + + public static $url = "http://host.docker.internal:5000/"; + public static $option; + + + public static function setOption($method, $data){ + if(!is_null($data)){ + static::$option = [ + 'http' => [ + 'method' => $method, + 'header' => 'Content-Type: application/json', + 'content' => json_encode($data), + ], + ]; + }else{ + static::$option = [ + 'http' => [ + 'method' => $method, + 'header' => 'Content-Type: application/json', + ], + ]; + } + + } + + public static function setEndpoint($apiEndpoint){ + static::$apiEndpoint = $apiEndpoint; + + } + + public static function call(){ + $context = stream_context_create(static::$option); + $response = file_get_contents(static::$url . static::$apiEndpoint, false, $context); + return $response; + } + + +} +?>