From cea43655838450250502a42c6ce57d76902fa56c Mon Sep 17 00:00:00 2001
From: Bitha17 <16521076@mahasiswa.itb.ac.id>
Date: Mon, 9 Oct 2023 11:36:21 +0700
Subject: [PATCH] edit: pembelian request method and routing

---
 app/Controllers/PembelianController.php | 20 +++++---------------
 app/Controllers/TicketController.php    |  2 +-
 app/Views/pembelian/pembelian.php       |  6 ++----
 app/router.php                          |  4 ++--
 4 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/app/Controllers/PembelianController.php b/app/Controllers/PembelianController.php
index 93d5aa3..fa33e13 100644
--- a/app/Controllers/PembelianController.php
+++ b/app/Controllers/PembelianController.php
@@ -68,32 +68,22 @@ class PembelianController {
         ];
     }
 
-    // Returns true if purchase succeeds
     public function purchaseTicket($ticketId,$userId) {
-        // $purchases = $this->getAllPembelian();
-        // foreach ($purchases as $purchase) :
-        //     echo $purchase['pembelian_id'] . ': ' . $purchase['user_id'] . ', ' . $purchase['ticket_id'] . ', ' . $purchase['pembelian_created_time']."\n";
-        // endforeach;
-
         $createdTime = date("Y-m-d H:i:s");
         $this->createPembelian($ticketId,$userId,$createdTime);
-        // $purchases = $this->getAllPembelian();
-        // foreach ($purchases as $purchase) :
-        //     echo $purchase['pembelian_id'] . ': ' . $purchase['user_id'] . ', ' . $purchase['ticket_id'] . ', ' . $purchase['pembelian_created_time']."\n";
-        // endforeach;
     }
 
     public function handleRequest() {
-        if (isset($_GET['purchaseAction'])) {
-            if ($_GET['purchaseAction'] === 'purchaseTicket') {
-                unset($_GET['purchaseAction']);
+        if (isset($_POST['purchaseAction'])) {
+            if ($_POST['purchaseAction'] === 'purchaseTicket') {
+                unset($_POST['purchaseAction']);
                 $ticketId = $_POST['ticketId'];
                 $userId = $_POST['userId'];
                 $this->purchaseTicket($ticketId,$userId);
-                header("Location: /app/Views/home/home.php");
+                header("Location: /app/Views/history/history.php");
                 ob_end_flush();
             } else {
-                // Handle other actions here, if needed
+                // others
             }
         }
     }
diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php
index fe3bfbb..0c5c8f0 100644
--- a/app/Controllers/TicketController.php
+++ b/app/Controllers/TicketController.php
@@ -54,7 +54,7 @@ class TicketController {
         if (isset($_GET['ticketAction'])) {
             if ($_GET['ticketAction'] === 'getTicket') {
                 unset($_GET['ticketAction']);
-                $eventId = $_POST['eventId'];
+                $eventId = $_GET['eventId'];
                 $this->getEventTicketDetails($eventId);
                 // header("Location: Views/pembelian/pembelian.php");
             } else {
diff --git a/app/Views/pembelian/pembelian.php b/app/Views/pembelian/pembelian.php
index 2cfe244..136754b 100644
--- a/app/Views/pembelian/pembelian.php
+++ b/app/Views/pembelian/pembelian.php
@@ -44,12 +44,10 @@
                         
                         <!-- Purchase Form -->
                     </div>    
-                    <form id="purchaseForm" method="post" action="/app/router.php?purchaseAction=purchaseTicket">
+                    <form id="purchaseForm" method="post" action="/app/router.php">
                         <input type="hidden" name="ticketId" value="<?php echo $ticket['ticket_id']; ?>">
                         <input type="hidden" name="userId" value="<?php echo $_SESSION['user_id']; ?>">
-                        
-                        <!-- Additional form fields or options can be added here -->
-                        
+                        <input type="hidden" name="purchaseAction" value="purchaseTicket">
                         <button type="button" id="confirmPurchaseBtn">Confirm Purchase</button>
                     </form>
                 </div>
diff --git a/app/router.php b/app/router.php
index 4a9b67a..7156e5c 100644
--- a/app/router.php
+++ b/app/router.php
@@ -13,11 +13,11 @@ $userController = new UserController();
 if ($_SERVER["REQUEST_METHOD"] == "POST") {
     if (isset($_POST["eventAction"])) {
         $eventController->handleRequest();
-    } elseif (isset($_GET["ticketAction"])) {
+    } elseif (isset($_POST["ticketAction"])) {
         $ticketController->handleRequest();
     } elseif (isset($_POST["userAction"])) {
         $userController->handleRequest();
-    } elseif (isset($_GET["purchaseAction"])) {
+    } elseif (isset($_POST["purchaseAction"])) {
         $pembelianController->handleRequest();
     }
 
-- 
GitLab