From 03da043be33ab2057eadcf486aa6cd761ed4ee1a Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Sat, 13 Jul 2024 17:59:54 +0200 Subject: [PATCH] Docs --- exam/api/docs/index.css | 3 +++ exam/api/docs/index.html | 11 ++++++++++- exam/api/index.php | 5 ++--- exam/api/posts/index.php | 26 +++++++++++++++++++++++++ exam/api/users/index.php | 13 ++++++++++++- exam/config/database.php | 9 +++++++++ exam/routes/routes.php | 6 +++++- exam/vendor/config/config.php | 7 +++++++ exam/vendor/database/database.php | 32 +++++++++++++++++++++++++++++++ 9 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 exam/api/docs/index.css create mode 100644 exam/api/posts/index.php create mode 100644 exam/config/database.php create mode 100644 exam/vendor/database/database.php diff --git a/exam/api/docs/index.css b/exam/api/docs/index.css new file mode 100644 index 0000000..88cb00c --- /dev/null +++ b/exam/api/docs/index.css @@ -0,0 +1,3 @@ +body { + background-color: red; +} \ No newline at end of file diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index 2fbdaa8..68a3df6 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -1 +1,10 @@ -DOCUMENTATION + + + + + + Calculator + + + + diff --git a/exam/api/index.php b/exam/api/index.php index e495dfe..8ed3009 100644 --- a/exam/api/index.php +++ b/exam/api/index.php @@ -1,4 +1,3 @@ prepare($query); + $stmt->execute(); + + Response::api($stmt->fetchAll()); +} diff --git a/exam/api/users/index.php b/exam/api/users/index.php index c032abf..5cc4ccb 100644 --- a/exam/api/users/index.php +++ b/exam/api/users/index.php @@ -11,5 +11,16 @@ switch ($method) { function get() { - Response::api("GET USERS"); + $db = Database::getInstance(); + + $query = + "SELECT + * + FROM + egb_benutzer"; + + $stmt = $db->prepare($query); + $stmt->execute(); + + Response::api($stmt->fetchAll()); } diff --git a/exam/config/database.php b/exam/config/database.php new file mode 100644 index 0000000..c70d477 --- /dev/null +++ b/exam/config/database.php @@ -0,0 +1,9 @@ + "usersql.zedat.fu-berlin.de", + "user" => "khofmann-sql", + "passwd" => "xz8c7m7p", + "database" => "khofmann-db1", + "charset" => "utf8", +]; diff --git a/exam/routes/routes.php b/exam/routes/routes.php index 8408996..c977975 100644 --- a/exam/routes/routes.php +++ b/exam/routes/routes.php @@ -4,7 +4,11 @@ $path = ltrim(str_replace(Config::getBasePath(), "", $_SERVER['REQUEST_URI']), " try { if (substr($path, 0, 3) === "api") { - require_once __DIR__ . "/../api/index.php"; + if (strpos($path, "docs") === false) { + require_once __DIR__ . "/../$path/index.php"; + } else { + Headers::redirect("index.html"); + } } else { require_once __DIR__ . "/../pages/index.html"; } diff --git a/exam/vendor/config/config.php b/exam/vendor/config/config.php index f686e9d..af3d89f 100644 --- a/exam/vendor/config/config.php +++ b/exam/vendor/config/config.php @@ -5,10 +5,12 @@ class Config private static $instances = []; private array $app; + private array $database; protected function __construct() { $this->app = require_once __DIR__ . "/../../config/app.php"; + $this->database = require_once __DIR__ . "/../../config/database.php"; } protected function __clone() @@ -34,4 +36,9 @@ class Config { return Config::getInstance()->app["basePath"]; } + + public static function getDatabase() + { + return Config::getInstance()->database; + } } diff --git a/exam/vendor/database/database.php b/exam/vendor/database/database.php new file mode 100644 index 0000000..ffda7ba --- /dev/null +++ b/exam/vendor/database/database.php @@ -0,0 +1,32 @@ + false, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ] + ); + } + + return self::$instances[$cls]; + } +}