From 191c56189bca5da32466a2273d5ae544f6f54cb9 Mon Sep 17 00:00:00 2001
From: Alexander Jason <alexanderjason526@gmail.com>
Date: Fri, 17 Nov 2023 05:45:27 +0700
Subject: [PATCH] feat: integrate rest to php

---
 app/components/Navbar.php                   | 16 ++++++++++++++++
 app/controllers/UserController.php          | 17 +++++++++++++++--
 app/pages/premium/PremiumCollectionPage.php | 18 ++++++++++--------
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/app/components/Navbar.php b/app/components/Navbar.php
index 87137ac..e76f3f0 100644
--- a/app/components/Navbar.php
+++ b/app/components/Navbar.php
@@ -38,6 +38,22 @@
                 </li>
                 <?php endif;?>
                 <?php endif;?>
+                <?php if(isset($_SESSION['username'])):?>
+                <?php if($_SESSION["role"]=='customer') :?>
+                <li>
+                    <a class="subscription" href="/user/subs">
+                        <img src="<?= BASE_URL ?>/icon/dashboard.svg" alt="Customer Icon">
+                        My Subscription
+                    </a>
+                </li>
+                <li>
+                    <a class="premium" href="/premium">
+                        <img src="<?= BASE_URL ?>/icon/genre.svg" alt="Genre Icon"> 
+                        Premium Collection
+                    </a>
+                </li>
+                <?php endif;?>
+                <?php endif;?>
             </ul>
             <?php if(isset($_SESSION['username'])):?>
                 <form method="POST"
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index 98d1aea..9b17add 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -18,8 +18,21 @@ class UserController extends Controller implements ControllerInterface
     //insert data
     public function subs()
     {
-        $mySubscriptionView = $this->view('user', 'MySubscriptionView');
-        $mySubscriptionView->render();
+        if (!isset($_SESSION['username'])) {
+            http_response_code(301);
+            header("Location: /user/login", true, 301);
+            exit;
+        }
+
+        switch ($_SERVER['REQUEST_METHOD']) {
+            case 'GET':
+                // show the login page
+                $mySubscriptionView = $this->view('user', 'MySubscriptionView');
+                $mySubscriptionView->render();
+                break;
+            default:
+                throw new RequestException('Method Not Allowed', 405);
+        }
     }
 
     public function login() 
diff --git a/app/pages/premium/PremiumCollectionPage.php b/app/pages/premium/PremiumCollectionPage.php
index f8617b2..1ae4597 100644
--- a/app/pages/premium/PremiumCollectionPage.php
+++ b/app/pages/premium/PremiumCollectionPage.php
@@ -26,19 +26,21 @@
             <thead>
                 <tr>
                     <th>Id</th>
-                    <th>Book Title</th>
-                    <th>Author</th>
+                    <th>Curator Collection</th>
+                    <th>Details</th>
                 </tr>
             </thead>
             <?php
-            
-            $authors = $this->data['authors'];
+            $raw_data = file_get_contents('http://host.docker.internal:8040/api/curator-collection');
+            $data = json_decode($raw_data, true);
+            echo var_dump($data);
+            $collections = $data['found'];
 
-            foreach ($authors as $author) {
+            foreach ($collections as $collection) {
                 echo "<tr>";
-                echo "<td>" . $author['author_id'] . "</td>";
-                echo "<td>" . $author['full_name'] . "</td>"; 
-                echo "<td>" . $author['full_name'] . "</td>"; 
+                echo "<td>" . $collection['collectionId'] . "</td>";
+                echo "<td>" . $collection['createdBy'] . "</td>"; 
+                echo '<td><a href="/premium/detail/' . $collection['collectionId'] .'">Edit</a></td>';
                 echo "</tr>";
             }
             ?>
-- 
GitLab