div TODOs
This commit is contained in:
35
app/modules/buildings/delete.php
Normal file
35
app/modules/buildings/delete.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* app/modules/buildings/delete.php
|
||||
*/
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'Methode nicht erlaubt']);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'ID fehlt']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$exists = $sql->single("SELECT id FROM buildings WHERE id = ?", "i", [$id]);
|
||||
if (!$exists) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['error' => 'Gebaeude nicht gefunden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $sql->set("DELETE FROM buildings WHERE id = ?", "i", [$id]);
|
||||
if ($rows === false) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Loeschen fehlgeschlagen']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['status' => 'ok', 'success' => true, 'rows' => $rows]);
|
||||
Reference in New Issue
Block a user