Add WebGIS project documentation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once dirname(__DIR__) . '/config.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'GET') {
|
||||
$stmt = $pdo->query("SELECT * FROM jalan");
|
||||
echo json_encode($stmt->fetchAll());
|
||||
} elseif ($method === 'POST') {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$stmt = $pdo->prepare("INSERT INTO jalan (nama_jalan, status, panjang, geojson) VALUES (?, ?, ?, ?)");
|
||||
if ($stmt->execute([$data['nama_jalan'], $data['status'], $data['panjang'], $data['geojson']])) {
|
||||
echo json_encode(["status" => "success", "id" => $pdo->lastInsertId()]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to add data"]);
|
||||
}
|
||||
} elseif ($method === 'PUT') {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$stmt = $pdo->prepare("UPDATE jalan SET nama_jalan = ?, status = ?, panjang = ?, geojson = ? WHERE id = ?");
|
||||
if ($stmt->execute([$data['nama_jalan'], $data['status'], $data['panjang'], $data['geojson'], $data['id']])) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to update data"]);
|
||||
}
|
||||
} elseif ($method === 'DELETE') {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$stmt = $pdo->prepare("DELETE FROM jalan WHERE id = ?");
|
||||
if ($stmt->execute([$data['id']])) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to delete data"]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user