Harden Project 01 public endpoints
This commit is contained in:
+18
-16
@@ -1,26 +1,28 @@
|
||||
<?php
|
||||
require_once '../../koneksi.php';
|
||||
require_admin_json();
|
||||
header('Content-Type: application/json');
|
||||
require_once '../../auth/helper.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Method tidak valid.']); exit;
|
||||
}
|
||||
require_admin_post();
|
||||
require_once '../../koneksi.php';
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'ID tidak valid.']); exit;
|
||||
json_error('ID tidak valid.', 400);
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("DELETE FROM choropleth_layers WHERE id = ?");
|
||||
$stmt->bind_param('i', $id);
|
||||
$stmt->execute();
|
||||
$affected = $stmt->affected_rows;
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
if ($affected === 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Layer tidak ditemukan.']); exit;
|
||||
if (!$stmt) {
|
||||
error_log('Project 01 choropleth delete prepare failed: ' . $conn->error);
|
||||
json_error('Gagal menghapus layer.', 500);
|
||||
}
|
||||
|
||||
echo json_encode(['status' => 'success']);
|
||||
$stmt->bind_param('i', $id);
|
||||
if (!$stmt->execute()) {
|
||||
error_log('Project 01 choropleth delete failed: ' . $stmt->error);
|
||||
json_error('Gagal menghapus layer.', 500);
|
||||
}
|
||||
|
||||
if ($stmt->affected_rows <= 0) {
|
||||
json_error('Layer tidak ditemukan.', 404);
|
||||
}
|
||||
|
||||
json_success();
|
||||
|
||||
Reference in New Issue
Block a user