mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 15:44:29 -06:00
Clean up, fix customerId issue, finish insert
This commit is contained in:
parent
e8698e360f
commit
c05bf0559a
|
@ -122,12 +122,10 @@ class CustomerController extends BaseController{
|
|||
if (! $this->validatePerson($input)) {
|
||||
return $this->unprocessableEntityResponse();
|
||||
}
|
||||
//return var_dump($input);
|
||||
|
||||
//remove customer_id field so it doesn't break
|
||||
unset($input['customer_id']);
|
||||
//return var_dump($input);
|
||||
//$modinput = json_encode($input);
|
||||
//$newinput = json_decode($modinput, TRUE);
|
||||
|
||||
$response = $this->customerModel->insertCustomer($input);
|
||||
return $response;
|
||||
}
|
||||
|
@ -168,10 +166,13 @@ class CustomerController extends BaseController{
|
|||
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request';
|
||||
return;
|
||||
}
|
||||
if (isset($this->arrQueryStringParams['customer_id'])) {
|
||||
$this->customerModel->customerId = $this->arrQueryStringParams['customer_id'];
|
||||
|
||||
$this->arrQueryStringParams = $this->getQueryStringParams();
|
||||
|
||||
if (isset($this->arrQueryStringParams['customerId'])) {
|
||||
$this->customerModel->customerId = $this->arrQueryStringParams['customerId'];
|
||||
$result = $this->customerModel->findByCustomerId();
|
||||
if (! $result) {
|
||||
if (!$result) {
|
||||
return $this->notFoundResponse();
|
||||
}
|
||||
$response = $this->customerModel->deleteCustomer();
|
||||
|
|
|
@ -115,14 +115,13 @@ class CustomerModel extends Database {
|
|||
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
||||
|
||||
$rowCount = $this->processStatement($query);
|
||||
//$result = (object) ['rowCount'=>$rowCount];
|
||||
return $rowCount;
|
||||
}
|
||||
|
||||
public function deleteCustomer()
|
||||
{
|
||||
$rowCount = $this->processStatement("DELETE FROM customer WHERE customer_id = ?", [$this->customerId]);
|
||||
$result = (object) ['rowCount'=>$rowCount];
|
||||
return $result;
|
||||
$query = "DELETE FROM customer WHERE customer_id = " . $this->customerId;
|
||||
$rowCount = $this->processStatement($query);
|
||||
return $rowCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,15 @@ class Database {
|
|||
public function processQuery($query = "", $params = [])
|
||||
{
|
||||
try {
|
||||
$stmt = $this->executeQuery( $query, $params );
|
||||
$stmt = $this->connection->prepare( $query );
|
||||
if($stmt === false) {
|
||||
throw New Exception("Unable to do prepared statement: " . $query);
|
||||
}
|
||||
if( $params ) {
|
||||
$stmt->bind_param($params[0], $params[1]);
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $result;
|
||||
|
@ -59,19 +67,19 @@ class Database {
|
|||
public function processStatement($query = "")
|
||||
{
|
||||
try {
|
||||
//return var_dump($query);
|
||||
//Prepare the statement
|
||||
$stmt = $this->connection->stmt_init();
|
||||
$stmt = $this->connection->prepare($query);
|
||||
if($stmt === false) {
|
||||
throw New Exception("Unable to prepare the statement: " . $query);
|
||||
}
|
||||
//return var_dump($query);
|
||||
|
||||
$result = $stmt->execute();
|
||||
if($result === false) {
|
||||
throw New Exception("Unable to execute the statement: " . $query);
|
||||
}
|
||||
|
||||
//$rowCount = $this->executeStatement($stmt);
|
||||
$rowCount = $this->connection->affected_rows;
|
||||
if($rowCount < 1)
|
||||
{
|
||||
|
@ -85,19 +93,4 @@ class Database {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function executeStatement(&$stmt)
|
||||
{
|
||||
try {
|
||||
$result = $stmt->execute();
|
||||
if($result === false) {
|
||||
throw New Exception("Unable to execute the statement.");
|
||||
}
|
||||
|
||||
$rowCount = $this->connection->affected_rows;
|
||||
return $rowCount;
|
||||
} catch(Exception $e) {
|
||||
throw New Exception( $e->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user