first commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user