Refactor entry API: consolidate entry handling, update naming conventions, and enhance error reporting
This commit is contained in:
1 parent
205f2e2f73
commit
ad9290d2ad
9 files changed
+72
-12
No files matched your search
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
// Set internal to false so that the answer goes to the client
|
||||||
|
if (!isset($internal)) {
|
||||||
|
$internal = false;
|
||||||
|
define("API_DIR", "../");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load Main Library
|
||||||
|
require_once API_DIR . "api.php";
|
||||||
|
|
||||||
|
$api = new gbAPI(true, $internal);
|
||||||
|
|
||||||
|
$input = $api->getInput();
|
||||||
|
|
||||||
|
|
||||||
|
// Check given Status
|
||||||
|
if (!isset($input["status"])) {
|
||||||
|
$api->answer(400, [
|
||||||
|
"error" => "missing_fields",
|
||||||
|
"error_text" => "Some fields are missing"
|
||||||
|
], true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($status !== 0 && $status !== 1 && $status !== 2) {
|
||||||
|
$api->answer(400, [
|
||||||
|
"error" => "status_invalid",
|
||||||
|
"error_text" => "The given status is invalid."
|
||||||
|
], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$command = "SELECT * FROM entrys WHERE status = :status";
|
||||||
|
|
||||||
|
$response = $api->dbCommand($command, true, true, [
|
||||||
|
":status" => $status
|
||||||
|
]);
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ class HTMLLoader {
|
|||||||
|
|
||||||
function setPage($page) {
|
function setPage($page) {
|
||||||
if (!array_key_exists($page, $this->template_conf)) {
|
if (!array_key_exists($page, $this->template_conf)) {
|
||||||
$this->showError("Page " . $page . " for template " . $this->template . " not found.");
|
$this->showError('Page <span class="code">' . $page . '</span> for template <span class="code">' . $this->template . '</span> not found.');
|
||||||
}else{
|
}else{
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
}
|
}
|
||||||
@@ -93,6 +93,10 @@ class HTMLLoader {
|
|||||||
|
|
||||||
$page = $tempalte_conf[$this->page];
|
$page = $tempalte_conf[$this->page];
|
||||||
|
|
||||||
|
if (!is_file(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"])) {
|
||||||
|
$this->showError('HTML File <span class="code">' . $page["html_file"] . '</span> for page <span class="code">' . $page["name"] . '</span> in template <span class="code">' . $template . '</span> does not exists.');
|
||||||
|
}
|
||||||
|
|
||||||
$html = file_get_contents(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"]);
|
$html = file_get_contents(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"]);
|
||||||
|
|
||||||
if ($showAppName) {
|
if ($showAppName) {
|
||||||
|
|||||||
+6
-2
@@ -13,12 +13,16 @@ require FRONTEND_PATH . "html_loader.php";
|
|||||||
$htmlLoader = new HTMLLoader();
|
$htmlLoader = new HTMLLoader();
|
||||||
|
|
||||||
// Build Entry Page
|
// Build Entry Page
|
||||||
$htmlLoader->setPage("entrys_frontend");
|
$htmlLoader->setPage("entries_frontend");
|
||||||
|
|
||||||
// Get entrys
|
// Get entrys
|
||||||
$call = new APICall("entrys/get.php");
|
$call = new APICall("entry/get.php");
|
||||||
$response = $call->response;
|
$response = $call->response;
|
||||||
|
|
||||||
|
if ($call->getError() !== false) {
|
||||||
|
$htmlLoader->showError("Entry API Returned an error: " . $call->getError());
|
||||||
|
}
|
||||||
|
|
||||||
if ($response["data"]["empty"]) {
|
if ($response["data"]["empty"]) {
|
||||||
$html_block = "<p>There aren'n any entrys yet. Be the first one!</p>";
|
$html_block = "<p>There aren'n any entrys yet. Be the first one!</p>";
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
+9
-1
@@ -46,7 +46,7 @@ class APICall {
|
|||||||
|
|
||||||
// Check Path
|
// Check Path
|
||||||
if (!is_file(API_DIR . $path)) {
|
if (!is_file(API_DIR . $path)) {
|
||||||
$this->error("API Path invalid.");
|
$this->error = "API Path invalid.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,4 +58,12 @@ class APICall {
|
|||||||
|
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getError() {
|
||||||
|
if (isset($this->error)) {
|
||||||
|
return $this->error;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<md-icon-button id="toggle" aria-label="Menü ein-/ausklappen">
|
<md-icon-button id="toggle" aria-label="Menü ein-/ausklappen">
|
||||||
<md-icon>menu</md-icon>
|
<md-icon>menu</md-icon>
|
||||||
</md-icon-button>
|
</md-icon-button>
|
||||||
<span class="title">Dashboard</span>
|
<span class="md-typescale-body-large title">%appname%</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<md-list>
|
<md-list>
|
||||||
@@ -117,7 +117,14 @@
|
|||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<main class="content">
|
<main class="content">
|
||||||
<h1>Dashboard</h1>
|
<h1 class="md-typescale-display-large">%appname%</h1>
|
||||||
|
<h3 class="md-typescale-display-medium">Entrys</h3>
|
||||||
|
<md-list>
|
||||||
|
<md-list-item>
|
||||||
|
<div slot="headline">Cucumber</div>
|
||||||
|
<div slot="supporting-text">Cucumbers are long green fruits that are just as long as this multi-line description</div>
|
||||||
|
</md-list-item>
|
||||||
|
</md-list>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@
|
|||||||
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
|
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<title>%appname% // Entrys</title>
|
<title>%appname% // Entries</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
name = document.getElementById("entry_name").value;
|
name = document.getElementById("entry_name").value;
|
||||||
text = document.getElementById("entry_text").value;
|
text = document.getElementById("entry_text").value;
|
||||||
|
|
||||||
fetch("/api/entrys/add.php", {
|
fetch("/api/entry/add.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: name,
|
name: name,
|
||||||
@@ -15,10 +15,10 @@
|
|||||||
"css_files":[]
|
"css_files":[]
|
||||||
},
|
},
|
||||||
|
|
||||||
"entrys_frontend":{
|
"entries_frontend":{
|
||||||
"name":"entrys_frontend",
|
"name":"entries_frontend",
|
||||||
"dir_name":"entrys_frontend",
|
"dir_name":"entries_frontend",
|
||||||
"html_file":"entrys_frontend.html",
|
"html_file":"entries_frontend.html",
|
||||||
"css_files":[]
|
"css_files":[]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user