From b8ced4331c8dcbda3b43f76f672198dffee689b9 Mon Sep 17 00:00:00 2001
From: Kenneth Dave <dave.bahana@gmail.com>
Date: Sat, 7 Oct 2023 19:20:23 +0700
Subject: [PATCH] feat: adding initial data examples for testing

---
 app/core/Database.php | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/app/core/Database.php b/app/core/Database.php
index 652e4b0..a7de478 100644
--- a/app/core/Database.php
+++ b/app/core/Database.php
@@ -47,10 +47,42 @@ class Database
             $this->statement->bindParam(":password", $password, PDO::PARAM_STR);
             $this->statement->bindParam(":admin", $admin, PDO::PARAM_BOOL);
 
-    // Execute the query
-    $this->statement->execute();
-        } catch (PDOException $e) {
-            die($e->getMessage());
+            // TESTING AUTHOR & BOOK
+            // Insert two authors (John and Ken)
+            $authors = ["John", "Ken"];
+            foreach ($authors as $authorName) {
+                $query = "INSERT IGNORE INTO author (name) VALUES (:authorName)";
+                $this->query($query);
+                $this->statement->bindParam(":authorName", $authorName, PDO::PARAM_STR);
+                $this->statement->execute();
+            }
+
+            // Insert 5 books, 3 by John and 2 by Ken
+            $books = [
+                ["title" => "Book 1", "author_id" => 1, "audio_path" => "audio1.mp3", "image_path" => "image1.jpg", "category" => "Category A"],
+                ["title" => "Book 2", "author_id" => 1, "audio_path" => "audio2.mp3", "image_path" => "image2.jpg", "category" => "Category B"],
+                ["title" => "Book 3", "author_id" => 1, "audio_path" => "audio3.mp3", "image_path" => "image3.jpg", "category" => "Category C"],
+                ["title" => "Book 4", "author_id" => 2, "audio_path" => "audio4.mp3", "image_path" => "image4.jpg", "category" => "Category D"],
+                ["title" => "Book 5", "author_id" => 2, "audio_path" => "audio5.mp3", "image_path" => "image5.jpg", "category" => "Category E"]
+            ];
+
+            foreach ($books as $book) {
+                $query = "INSERT IGNORE INTO book (title, author_id, audio_path, image_path, category) 
+                        VALUES (:title, :author_id, :audio_path, :image_path, :category)";
+                $this->query($query);
+                $this->statement->bindParam(":title", $book['title'], PDO::PARAM_STR);
+                $this->statement->bindParam(":author_id", $book['author_id'], PDO::PARAM_INT);
+                $this->statement->bindParam(":audio_path", $book['audio_path'], PDO::PARAM_STR);
+                $this->statement->bindParam(":image_path", $book['image_path'], PDO::PARAM_STR);
+                $this->statement->bindParam(":category", $book['category'], PDO::PARAM_STR);
+                $this->statement->execute();
+            }
+
+
+            // Execute the query
+            $this->statement->execute();
+            } catch (PDOException $e) {
+                die($e->getMessage());
         }
     }
 
-- 
GitLab