Files
SIG_WEBGIS_Nur_Ichsanul_Alif/api/bantuan.php
T
2026-06-10 22:46:10 +07:00

80 lines
1.4 KiB
PHP

<?php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../config/helpers.php';
handlePreflight();
$method = getMethod();
$db = getDB();
switch ($method) {
case 'GET':
if(isset($_GET['point_id'])){
$stmt = $db->prepare(
"SELECT *
FROM bantuan
WHERE point_id=?
ORDER BY tanggal_bantuan DESC"
);
$stmt->execute([
(int)$_GET['point_id']
]);
jsonResponse(
$stmt->fetchAll()
);
}
break;
case 'POST':
$body = getRequestBody();
$stmt = $db->prepare(
"INSERT INTO bantuan
(
point_id,
jenis_bantuan,
nominal,
tanggal_bantuan,
instansi_pemberi,
keterangan
)
VALUES
(?, ?, ?, ?, ?, ?)"
);
$stmt->execute([
$body['point_id'],
$body['jenis_bantuan'],
$body['nominal'],
$body['tanggal_bantuan'],
$body['instansi_pemberi'],
$body['keterangan']
]);
jsonResponse([
'message'=>'Bantuan berhasil ditambahkan'
],201);
break;
default:
jsonResponse([
'error'=>'Method not allowed'
],405);
}