JSON output improved

This commit is contained in:
paolo
2016-04-22 11:08:38 +02:00
parent 4e02a1105b
commit 346b8c82e1
6 changed files with 71 additions and 69 deletions
@@ -39,26 +39,14 @@ class Person extends REST_Controller
$result = $this->PersonModel->getPerson($personID, $code, $email);
if(!is_null($result) && $result->num_rows() > 0)
if(is_object($result))
{
if($result->num_rows() > 1)
{
$payload = [
'success' => TRUE,
'message' => 'People found',
'data' => $result->result()[0]
];
$httpstatus = REST_Controller::HTTP_OK;
}
else if($result->num_rows() == 1)
{
$payload = [
'success' => TRUE,
'message' => 'Person found',
'data' => $result->result()[0]
];
$httpstatus = REST_Controller::HTTP_OK;
}
$payload = [
'success' => TRUE,
'message' => 'People found',
'data' => $result->result()
];
$httpstatus = REST_Controller::HTTP_OK;
}
else
{
@@ -98,6 +86,32 @@ class Person extends REST_Controller
}
$this->response($payload, $httpstatus);
}
/**
*
*/
public function postInterestedStudent()
{
$result = $this->PersonModel->saveInterestedStudent($this->post());
if($result === TRUE)
{
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Interested student saved.'
];
}
else
{
$payload = [
'success' => false,
'message' => 'Could not save interested student.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
}
/**
* @return void
@@ -140,30 +154,4 @@ class Person extends REST_Controller
$this->response($payload, $httpstatus);
}
/**
*
*/
public function postInterestedStudent()
{
$result = $this->PersonModel->saveInterestedStudent($this->post());
if($result === TRUE)
{
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Interested student saved.'
];
}
else
{
$payload = [
'success' => false,
'message' => 'Could not save interested student.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
}
}