diff --git a/src/app/components/creator/creatorlist.php b/src/app/components/creator/creatorlist.php index 3b57395b229c9965c516863ba2eb961cd6ad91d1..310a0cc2aff212ae52aea75bf80594da08a825e5 100644 --- a/src/app/components/creator/creatorlist.php +++ b/src/app/components/creator/creatorlist.php @@ -41,9 +41,9 @@ <p class="creator-username"><?= $creator['username'] ?></p> </div> <div class="button-div"> - <?php if ($creator['subs_status'] == "no"): ?> + <?php if ($creator['subsStatus'] == "no"): ?> <button id="<?= $creator['id']?>" name="subs-button" type="button" class="button green">Subscribe</button> - <?php elseif ($creator['subs_status'] == "yes"): ?> + <?php elseif ($creator['subsStatus'] == "yes"): ?> <!-- TODO: FIX URL --> <a href="<?= BASE_URL ."/../creator/recipe/" . $creator['id']?>" aria-label="<?= 'Creator ' . $creator['id']?> . '\'s content'"> <button id="view-button" type="button" class="button green">All Recipes</button> diff --git a/src/app/config/config.php b/src/app/config/config.php index 451e8ea63d9f02bc46ed0b908e340e1d2a0cfa34..554e3ba5e68313e479e8da67f50f063d797e7c22 100644 --- a/src/app/config/config.php +++ b/src/app/config/config.php @@ -3,6 +3,7 @@ // Database connection define('BASE_URL', 'http://localhost:8008/public'); define('STORAGE_URL', 'http://localhost:8008/storage'); +define('REST_URL', 'http://cooklyst-rest-api:3000'); define('DB_HOST', $_ENV['MYSQL_HOST']); define('DB_NAME', $_ENV['MYSQL_DATABASE']); define('DB_USER', $_ENV['MYSQL_USER'] ?? 'root'); @@ -27,3 +28,6 @@ define('IMAGE_FORMAT', [ ]); define('MAX_UPLOAD_SIZE', 40 * 1024 * 1024); + +// key +define('REST_KEY', 'php'); diff --git a/src/app/controllers/CreatorController.php b/src/app/controllers/CreatorController.php index 2d86b7f2a97ce839bb9c102c8a7528c612bd6a60..cbfb405502fc70544010425b81dc9ae72bba7a7c 100644 --- a/src/app/controllers/CreatorController.php +++ b/src/app/controllers/CreatorController.php @@ -13,41 +13,61 @@ class CreatorController extends Controller implements ControllerInterface // TODO: Get data from REST, check using user_id - $data = [ - 'user_id' => $user_id, - 'creators' => [ - [ - 'id' => 1, - 'name' => 'Creator 1', - 'username' => 'username1', - 'subs_status' => "no" - ], - [ - 'id' => 2, - 'name' => 'Creator 2', - 'username' => 'username2', - 'subs_status' => "yes" - ], - [ - 'id' => 3, - 'name' => 'Creator 3', - 'username' => 'username3', - 'subs_status' => "waiting" - ], - [ - 'id' => 4, - 'name' => 'Creator 4', - 'username' => 'username4', - 'subs_status' => "no" - ], - [ - 'id' => 5, - 'name' => 'Creator 5', - 'username' => 'username5', - 'subs_status' => "no" - ], - ] - ]; + $url = REST_URL . '/pro/creator'; + $data = json_encode(["requesterID" => $user_id]); + $headers = ['Content-Type: application/json', 'x-api-key: ' . REST_KEY]; + + $ch = curl_init($url); + curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $data, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => $headers, + ]); + + $response = curl_exec($ch); + $arrayResponse = json_decode($response, true); + // $arrayResponse['user_id'] = $user_id; + $data = ['user_id' => $user_id, 'creators' => $arrayResponse['data']]; + // print_r($data); + + + // $data = [ + // 'user_id' => $user_id, + // 'creators' => [ + // [ + // 'id' => 1, + // 'name' => 'Creator 1', + // 'username' => 'username1', + // 'subs_status' => "no" + // ], + // [ + // 'id' => 2, + // 'name' => 'Creator 2', + // 'username' => 'username2', + // 'subs_status' => "yes" + // ], + // [ + // 'id' => 3, + // 'name' => 'Creator 3', + // 'username' => 'username3', + // 'subs_status' => "waiting" + // ], + // [ + // 'id' => 4, + // 'name' => 'Creator 4', + // 'username' => 'username4', + // 'subs_status' => "no" + // ], + // [ + // 'id' => 5, + // 'name' => 'Creator 5', + // 'username' => 'username5', + // 'subs_status' => "no" + // ], + // ] + // ]; + $viewResult = $this->view("creator", "CreatorList", $data); @@ -75,7 +95,6 @@ class CreatorController extends Controller implements ControllerInterface throw new DisplayedException(400, "creator_id and email cannot be empty,"); } - // TODO: Send Request to SOAP $requestXml = ' <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> @@ -119,6 +138,7 @@ class CreatorController extends Controller implements ControllerInterface print $err; } else { curl_close($curl); + print $response; http_response_code(201); } diff --git a/src/public/javascript/creator/subscribemodals.js b/src/public/javascript/creator/subscribemodals.js index 2f113a5c2624b792bfa04adc4905c4e4b984a241..ce2f8afd81c1e94e7de8825868fb3230c8fcff61 100644 --- a/src/public/javascript/creator/subscribemodals.js +++ b/src/public/javascript/creator/subscribemodals.js @@ -77,7 +77,7 @@ form && xhr.onreadystatechange = function () { if (this.readyState === XMLHttpRequest.DONE) { if (this.status === 201) { - location.replace("./"); + location.replace("/creator"); } else { res.innerText = "An error occured."; res.className = "alert shown-error";