mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 15:34:30 -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)) {
|
if (! $this->validatePerson($input)) {
|
||||||
return $this->unprocessableEntityResponse();
|
return $this->unprocessableEntityResponse();
|
||||||
}
|
}
|
||||||
//return var_dump($input);
|
|
||||||
//remove customer_id field so it doesn't break
|
//remove customer_id field so it doesn't break
|
||||||
unset($input['customer_id']);
|
unset($input['customer_id']);
|
||||||
//return var_dump($input);
|
|
||||||
//$modinput = json_encode($input);
|
|
||||||
//$newinput = json_decode($modinput, TRUE);
|
|
||||||
$response = $this->customerModel->insertCustomer($input);
|
$response = $this->customerModel->insertCustomer($input);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
@ -168,10 +166,13 @@ class CustomerController extends BaseController{
|
||||||
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request';
|
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request';
|
||||||
return;
|
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();
|
$result = $this->customerModel->findByCustomerId();
|
||||||
if (! $result) {
|
if (!$result) {
|
||||||
return $this->notFoundResponse();
|
return $this->notFoundResponse();
|
||||||
}
|
}
|
||||||
$response = $this->customerModel->deleteCustomer();
|
$response = $this->customerModel->deleteCustomer();
|
||||||
|
|
|
@ -115,14 +115,13 @@ class CustomerModel extends Database {
|
||||||
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
||||||
|
|
||||||
$rowCount = $this->processStatement($query);
|
$rowCount = $this->processStatement($query);
|
||||||
//$result = (object) ['rowCount'=>$rowCount];
|
|
||||||
return $rowCount;
|
return $rowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteCustomer()
|
public function deleteCustomer()
|
||||||
{
|
{
|
||||||
$rowCount = $this->processStatement("DELETE FROM customer WHERE customer_id = ?", [$this->customerId]);
|
$query = "DELETE FROM customer WHERE customer_id = " . $this->customerId;
|
||||||
$result = (object) ['rowCount'=>$rowCount];
|
$rowCount = $this->processStatement($query);
|
||||||
return $result;
|
return $rowCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,15 @@ class Database {
|
||||||
public function processQuery($query = "", $params = [])
|
public function processQuery($query = "", $params = [])
|
||||||
{
|
{
|
||||||
try {
|
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);
|
$result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -58,20 +66,20 @@ class Database {
|
||||||
|
|
||||||
public function processStatement($query = "")
|
public function processStatement($query = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
//return var_dump($query);
|
||||||
//Prepare the statement
|
//Prepare the statement
|
||||||
$stmt = $this->connection->stmt_init();
|
$stmt = $this->connection->stmt_init();
|
||||||
$stmt = $this->connection->prepare($query);
|
$stmt = $this->connection->prepare($query);
|
||||||
if($stmt === false) {
|
if($stmt === false) {
|
||||||
throw New Exception("Unable to prepare the statement: " . $query);
|
throw New Exception("Unable to prepare the statement: " . $query);
|
||||||
}
|
}
|
||||||
//return var_dump($query);
|
|
||||||
$result = $stmt->execute();
|
$result = $stmt->execute();
|
||||||
if($result === false) {
|
if($result === false) {
|
||||||
throw New Exception("Unable to execute the statement: " . $query);
|
throw New Exception("Unable to execute the statement: " . $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
//$rowCount = $this->executeStatement($stmt);
|
|
||||||
$rowCount = $this->connection->affected_rows;
|
$rowCount = $this->connection->affected_rows;
|
||||||
if($rowCount < 1)
|
if($rowCount < 1)
|
||||||
{
|
{
|
||||||
|
@ -85,19 +93,4 @@ class Database {
|
||||||
}
|
}
|
||||||
return false;
|
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