Clean up, fix customerId issue, finish insert

This commit is contained in:
sctn4elk 2024-05-04 00:22:26 -05:00
parent e8698e360f
commit c05bf0559a
3 changed files with 23 additions and 30 deletions

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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() );
}
}
}