pertama dan terakhir
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* jalan.php
|
||||
* Tanggung Jawab: Menangani operasi CRUD untuk entitas Jalan (LineString).
|
||||
*/
|
||||
|
||||
require_once '../config/db.php';
|
||||
require_once '../utils/response_helper.php';
|
||||
|
||||
$pdo = Database::getConnection();
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT id, nama, jenis_jalan, created_at, ST_AsGeoJSON(geom) as geojson FROM jalan");
|
||||
$features = [];
|
||||
while ($row = $stmt->fetch()) {
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => json_decode($row['geojson']),
|
||||
'properties' => [
|
||||
'id' => $row['id'],
|
||||
'nama' => $row['nama'],
|
||||
'jenis_jalan' => $row['jenis_jalan'],
|
||||
'created_at' => $row['created_at']
|
||||
]
|
||||
];
|
||||
}
|
||||
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Data Jalan berhasil diambil');
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal mengambil data Jalan: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($input['nama']) || !isset($input['geometry'])) {
|
||||
sendError('Nama dan geometri wajib diisi');
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO jalan (nama, jenis_jalan, geom) VALUES (:nama, :jenis_jalan, ST_GeomFromGeoJSON(:geometry))";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':nama' => $input['nama'],
|
||||
':jenis_jalan' => $input['jenis_jalan'] ?? 'Lokal',
|
||||
':geometry' => json_encode($input['geometry'])
|
||||
]);
|
||||
sendSuccess(['id' => $pdo->lastInsertId()], 'Data Jalan berhasil disimpan', 201);
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal menyimpan Jalan: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) {
|
||||
sendError('ID Jalan wajib disertakan');
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM jalan WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
sendSuccess(null, 'Data Jalan berhasil dihapus');
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal menghapus Jalan: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
sendError('Method not allowed', 405);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* kavling.php
|
||||
* Tanggung Jawab: Menangani operasi CRUD untuk entitas Kavling (Polygon).
|
||||
*/
|
||||
|
||||
require_once '../config/db.php';
|
||||
require_once '../utils/response_helper.php';
|
||||
|
||||
$pdo = Database::getConnection();
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT id, nama_pemilik, luas, created_at, ST_AsGeoJSON(geom) as geojson FROM kavling");
|
||||
$features = [];
|
||||
while ($row = $stmt->fetch()) {
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => json_decode($row['geojson']),
|
||||
'properties' => [
|
||||
'id' => $row['id'],
|
||||
'nama_pemilik' => $row['nama_pemilik'],
|
||||
'luas' => $row['luas'],
|
||||
'created_at' => $row['created_at']
|
||||
]
|
||||
];
|
||||
}
|
||||
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Data Kavling berhasil diambil');
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal mengambil data Kavling: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($input['nama_pemilik']) || !isset($input['geometry'])) {
|
||||
sendError('Nama pemilik dan geometri wajib diisi');
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO kavling (nama_pemilik, luas, geom) VALUES (:nama_pemilik, :luas, ST_GeomFromGeoJSON(:geometry))";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':nama_pemilik' => $input['nama_pemilik'],
|
||||
':luas' => $input['luas'] ?? 0,
|
||||
':geometry' => json_encode($input['geometry'])
|
||||
]);
|
||||
sendSuccess(['id' => $pdo->lastInsertId()], 'Data Kavling berhasil disimpan', 201);
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal menyimpan Kavling: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) {
|
||||
sendError('ID Kavling wajib disertakan');
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM kavling WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
sendSuccess(null, 'Data Kavling berhasil dihapus');
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal menghapus Kavling: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
sendError('Method not allowed', 405);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* rumah_ibadah.php
|
||||
* Tanggung Jawab: Operasi CRUD Rumah Ibadah + Endpoint analisis jangkauan Haversine.
|
||||
*/
|
||||
|
||||
require_once '../config/db.php';
|
||||
require_once '../utils/response_helper.php';
|
||||
require_once '../utils/geo_helper.php';
|
||||
|
||||
$pdo = Database::getConnection();
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
if (isset($_GET['action']) && $_GET['action'] === 'jangkauan' && isset($_GET['id'])) {
|
||||
// Analisis Jangkauan Haversine
|
||||
$id = $_GET['id'];
|
||||
$radius = isset($_GET['radius']) ? (float) $_GET['radius'] : 1.0; // default 1 km
|
||||
|
||||
// Dapatkan koordinat rumah ibadah ini
|
||||
$stmt = $pdo->prepare("SELECT ST_AsGeoJSON(geom) as geojson FROM rumah_ibadah WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$rumah_ibadah = $stmt->fetch();
|
||||
|
||||
if (!$rumah_ibadah) sendError('Rumah ibadah tidak ditemukan', 404);
|
||||
|
||||
$geom = json_decode($rumah_ibadah['geojson'], true);
|
||||
$pusatLon = $geom['coordinates'][0];
|
||||
$pusatLat = $geom['coordinates'][1];
|
||||
|
||||
// Panggil geo_helper untuk mendapatkan warga miskin
|
||||
$warga = GeoHelper::getWargaDalamRadius($pdo, $pusatLat, $pusatLon, $radius);
|
||||
sendSuccess($warga, 'Data jangkauan berhasil dihitung');
|
||||
|
||||
} else {
|
||||
// GET Semua Rumah Ibadah (GeoJSON)
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT id, nama, agama, ST_AsGeoJSON(geom) as geojson FROM rumah_ibadah");
|
||||
$features = [];
|
||||
while ($row = $stmt->fetch()) {
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => json_decode($row['geojson']),
|
||||
'properties' => [
|
||||
'id' => $row['id'],
|
||||
'nama' => $row['nama'],
|
||||
'agama' => $row['agama']
|
||||
]
|
||||
];
|
||||
}
|
||||
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Data Rumah Ibadah');
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($input['nama']) || !isset($input['geometry'])) sendError('Validasi gagal');
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO rumah_ibadah (nama, agama, geom) VALUES (:nama, :agama, ST_GeomFromGeoJSON(:geometry))";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':nama' => $input['nama'],
|
||||
':agama' => $input['agama'] ?? 'Islam',
|
||||
':geometry' => json_encode($input['geometry'])
|
||||
]);
|
||||
sendSuccess(['id' => $pdo->lastInsertId()], 'Disimpan', 201);
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) sendError('ID dibutuhkan');
|
||||
$stmt = $pdo->prepare("DELETE FROM rumah_ibadah WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
sendSuccess(null, 'Dihapus');
|
||||
break;
|
||||
|
||||
default:
|
||||
sendError('Method not allowed', 405);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
require_once '../config/db.php';
|
||||
require_once '../utils/response_helper.php';
|
||||
|
||||
$pdo = Database::getConnection();
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT id, nama, deskripsi, buka_24_jam, created_at, ST_AsGeoJSON(geom) as geojson FROM spbu");
|
||||
$features = [];
|
||||
while ($row = $stmt->fetch()) {
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => json_decode($row['geojson']),
|
||||
'properties' => [
|
||||
'id' => $row['id'],
|
||||
'nama' => $row['nama'],
|
||||
'deskripsi' => $row['deskripsi'],
|
||||
'buka_24_jam' => (bool)$row['buka_24_jam'],
|
||||
'created_at' => $row['created_at']
|
||||
]
|
||||
];
|
||||
}
|
||||
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Data SPBU berhasil diambil');
|
||||
} catch (PDOException $e) { sendError('Gagal: ' . $e->getMessage(), 500); }
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($input['nama']) || !isset($input['geometry'])) sendError('Validasi gagal');
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO spbu (nama, deskripsi, buka_24_jam, geom) VALUES (:nama, :deskripsi, :buka_24_jam, ST_GeomFromGeoJSON(:geometry))";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':nama' => $input['nama'],
|
||||
':deskripsi' => $input['deskripsi'] ?? '',
|
||||
':buka_24_jam' => isset($input['buka_24_jam']) && $input['buka_24_jam'] ? 1 : 0,
|
||||
':geometry' => json_encode($input['geometry'])
|
||||
]);
|
||||
sendSuccess(['id' => $pdo->lastInsertId()], 'Disimpan', 201);
|
||||
} catch (PDOException $e) { sendError('Gagal: ' . $e->getMessage(), 500); }
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) sendError('ID dibutuhkan');
|
||||
$stmt = $pdo->prepare("DELETE FROM spbu WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
sendSuccess(null, 'Dihapus');
|
||||
break;
|
||||
|
||||
default:
|
||||
sendError('Method not allowed', 405);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* warga_miskin.php
|
||||
* Tanggung Jawab: Operasi CRUD untuk Warga Miskin.
|
||||
*/
|
||||
|
||||
require_once '../config/db.php';
|
||||
require_once '../utils/response_helper.php';
|
||||
|
||||
$pdo = Database::getConnection();
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT id, nama_kk, penghasilan, jumlah_tanggungan, ST_AsGeoJSON(geom) as geojson FROM warga_miskin");
|
||||
$features = [];
|
||||
while ($row = $stmt->fetch()) {
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => json_decode($row['geojson']),
|
||||
'properties' => [
|
||||
'id' => $row['id'],
|
||||
'nama_kk' => $row['nama_kk'],
|
||||
'penghasilan' => $row['penghasilan'],
|
||||
'jumlah_tanggungan' => $row['jumlah_tanggungan']
|
||||
]
|
||||
];
|
||||
}
|
||||
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Data Warga Miskin');
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($input['nama_kk']) || !isset($input['geometry'])) sendError('Validasi gagal');
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO warga_miskin (nama_kk, penghasilan, jumlah_tanggungan, geom) VALUES (:nama_kk, :penghasilan, :jumlah_tanggungan, ST_GeomFromGeoJSON(:geometry))";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([
|
||||
':nama_kk' => $input['nama_kk'],
|
||||
':penghasilan' => $input['penghasilan'] ?? 0,
|
||||
':jumlah_tanggungan' => $input['jumlah_tanggungan'] ?? 0,
|
||||
':geometry' => json_encode($input['geometry'])
|
||||
]);
|
||||
sendSuccess(['id' => $pdo->lastInsertId()], 'Disimpan', 201);
|
||||
} catch (PDOException $e) {
|
||||
sendError('Gagal: ' . $e->getMessage(), 500);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) sendError('ID dibutuhkan');
|
||||
$stmt = $pdo->prepare("DELETE FROM warga_miskin WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
sendSuccess(null, 'Dihapus');
|
||||
break;
|
||||
|
||||
default:
|
||||
sendError('Method not allowed', 405);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user