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
Executable
+47
@@ -0,0 +1,47 @@
|
||||
<?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(false, $internal);
|
||||
|
||||
// Get Entrys
|
||||
$command = "SELECT * FROM entrys WHERE status = :status ORDER BY date DESC";
|
||||
$result = $api->dbCommand($command, true, true, [":status" => 1]);
|
||||
|
||||
$entrys = [];
|
||||
|
||||
if (!$result) {
|
||||
$api->answer(200, [
|
||||
"entrys" => [],
|
||||
"empty" => true
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($result as $row) {
|
||||
$entry_name = $row["name"];
|
||||
$entry_text = $row["text"];
|
||||
$date = new DateTime($row["date"]);
|
||||
$entry_date = $date->format("d.m.Y H:i:s");
|
||||
|
||||
$entry = [
|
||||
"name" => $entry_name,
|
||||
"text" => $entry_text,
|
||||
"date" => $entry_date
|
||||
];
|
||||
|
||||
$entrys[] = $entry;
|
||||
}
|
||||
|
||||
$json = json_encode($entrys);
|
||||
|
||||
$api->answer(200, [
|
||||
"entrys" => $json,
|
||||
"empty" => false
|
||||
]);
|
||||
Reference in new issue
Block a user