feat: complete WebGIS implementation with nominal bantuan and cache busting
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// ================================================================
|
||||
// API: Anggota Keluarga
|
||||
// ================================================================
|
||||
require_once __DIR__ . '/../config/database.php';
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
$db = getDB();
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : null;
|
||||
$pid = isset($_GET['penduduk_id']) ? (int)$_GET['penduduk_id'] : null;
|
||||
|
||||
if ($method === 'GET') {
|
||||
if (!$pid) jsonResponse(['success' => false, 'message' => 'penduduk_id wajib'], 400);
|
||||
$stmt = $db->prepare("SELECT * FROM anggota_keluarga WHERE penduduk_id = ? ORDER BY id");
|
||||
$stmt->execute([$pid]);
|
||||
jsonResponse(['success' => true, 'data' => $stmt->fetchAll()]);
|
||||
}
|
||||
|
||||
if ($method === 'POST') {
|
||||
$body = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
if (empty($body['penduduk_id']) || empty($body['nama'])) {
|
||||
jsonResponse(['success' => false, 'message' => 'penduduk_id dan nama wajib'], 422);
|
||||
}
|
||||
$stmt = $db->prepare("INSERT INTO anggota_keluarga (penduduk_id,nama,hubungan,umur,pekerjaan,keterangan) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([
|
||||
(int)$body['penduduk_id'],
|
||||
sanitize($body['nama'] ?? ''),
|
||||
sanitize($body['hubungan'] ?? ''),
|
||||
!empty($body['umur']) ? (int)$body['umur'] : null,
|
||||
sanitize($body['pekerjaan'] ?? ''),
|
||||
sanitize($body['keterangan'] ?? ''),
|
||||
]);
|
||||
jsonResponse(['success' => true, 'id' => $db->lastInsertId()], 201);
|
||||
}
|
||||
|
||||
if ($method === 'DELETE') {
|
||||
if (!$id) jsonResponse(['success' => false, 'message' => 'id wajib'], 400);
|
||||
$stmt = $db->prepare("DELETE FROM anggota_keluarga WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
jsonResponse(['success' => true]);
|
||||
}
|
||||
|
||||
jsonResponse(['success' => false, 'message' => 'Method tidak didukung'], 405);
|
||||
Reference in New Issue
Block a user