76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Darah extends REST_Controller
|
|
{
|
|
|
|
public function darah_post()
|
|
{
|
|
$id_user = $this->post("id_user");
|
|
$status = $this->post("status");
|
|
$tanggal = $this->post("tanggal");
|
|
|
|
|
|
$data = array(
|
|
'status' => $status,
|
|
'tanggal' => $tanggal,
|
|
'id_user' => $id_user,
|
|
// Menggunakan id_user dari tabel user
|
|
);
|
|
|
|
if ($this->db->insert('darah', $data)) {
|
|
$insert_id = $this->db->insert_id(); // Mendapatkan ID konsumsi yang baru saja dimasukkan
|
|
$response = array(
|
|
'field' => 'id_darah',
|
|
'message' => $insert_id
|
|
);
|
|
} else {
|
|
$response = array(
|
|
'status' => 500,
|
|
'message' => "INTERNAL_SERVER_ERROR"
|
|
);
|
|
}
|
|
|
|
$status_response = array(
|
|
'status' => 200,
|
|
'message' => "OK"
|
|
);
|
|
|
|
$final_response = array("response" => $response, "message" => $status_response);
|
|
$this->response($final_response);
|
|
}
|
|
|
|
public function tambahdarah_get()
|
|
{
|
|
$id_user = $this->get("id_user");
|
|
$tanggal = $this->get("tanggal");
|
|
|
|
if (!$id_user || !$tanggal) {
|
|
$response = array(
|
|
'status' => 400,
|
|
'message' => "Bad Request. id_user dan tanggal harus diisi."
|
|
);
|
|
} else {
|
|
$this->db->where('id_user', $id_user);
|
|
$this->db->where('tanggal', $tanggal);
|
|
$query = $this->db->get('darah');
|
|
|
|
if ($query->num_rows() > 0) {
|
|
$result = $query->result_array();
|
|
$response = array(
|
|
'status' => 200,
|
|
'message' => "OK",
|
|
'data' => $result
|
|
);
|
|
} else {
|
|
$response = array(
|
|
'status' => 404,
|
|
'message' => "Data tidak ditemukan."
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->response($response);
|
|
}
|
|
|
|
} |