diff --git a/Controller/API/AttributeController.php b/Controller/API/AttributeController.php index 0d9c73c..427ed8b 100644 --- a/Controller/API/AttributeController.php +++ b/Controller/API/AttributeController.php @@ -105,7 +105,7 @@ class AttributeController extends BaseController { } $jsonPayload = file_get_contents('php://input'); $input = json_decode($jsonPayload, TRUE); - + if (! $this->validateAttribute($input)) { return $this->unprocessableEntityResponse("validateAttribute"); } @@ -113,11 +113,12 @@ class AttributeController extends BaseController { if ($input['LOYALTY_MEMBER_ID'] != null) { $this->attributeModel->memberId = $input['LOYALTY_MEMBER_ID']; $this->attributeModel->attributeId = $input['LOYALTY_ATTRIBUTE_ID']; + $result = $this->attributeModel->findMemberAttribute(); if (! $result) { return $this->notFoundResponse("attributeModel->findMemberAttribute"); } - + $response = $this->attributeModel->updateMemberAttribute($input); unset($this->attributeModel->memberId); } else { diff --git a/Model/AttributeModel.php b/Model/AttributeModel.php index 4c894ff..52787f9 100644 --- a/Model/AttributeModel.php +++ b/Model/AttributeModel.php @@ -24,7 +24,10 @@ class AttributeModel extends Database { public function findMemberAttribute() { - return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ? AND loyalty_attribute_id = ?", ["ii", $this->memberId, $this->attributeId]); + $query = "SELECT * FROM loyalty_member_view WHERE loyalty_member_id = " . $this->memberId; + $query .= " AND loyalty_attribute_id = " . $this->attributeId; + + return $this->processQuery($query); } public function insertAttribute($inputModel) @@ -64,15 +67,21 @@ class AttributeModel extends Database { "LOYALTY_VALUE": "http://localhost/CustomerRewardsRESTAPI/public/images/1.jpg" } */ + $keys = array_keys($jsonPayLoad); $n = count($keys); - $query .= "CALL update_member_attribute_proc (" . $jsonPayLoad[$keys[0]] . ", "; + $query = "CALL update_loyalty_member_attribute_proc (" . $jsonPayLoad[$keys[0]] . ", "; for($i = 1; $i < $n-1; $i++) { - $query .= "'" . $jsonPayLoad[$keys[$i]] . "', "; + if($i == 3) { + $query .= $jsonPayLoad[$keys[$i]] . ", "; + } + else { + $query .= "'" . $jsonPayLoad[$keys[$i]] . "', "; + } } $query .= $jsonPayLoad[$keys[$i]] . ")"; - + $rowCount = $this->processStatement($query); return $rowCount; } diff --git a/Model/CustomerModel.php b/Model/CustomerModel.php index 5e2ff3e..6fd6e2e 100644 --- a/Model/CustomerModel.php +++ b/Model/CustomerModel.php @@ -69,7 +69,7 @@ class CustomerModel extends Database { $query .= "'" . $jsonPayLoad[$keys[$i]] . "', "; } $query .= $jsonPayLoad[$keys[$i]] . ")"; - + //return var_dump($query); $rowCount = $this->processStatement($query); return $rowCount; } diff --git a/Model/Database.php b/Model/Database.php index 7c8e8ad..8b668c1 100644 --- a/Model/Database.php +++ b/Model/Database.php @@ -100,7 +100,8 @@ class Database { { $response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Query'; $response['body'] = json_encode([ - 'error' => 'Invalid query' + 'error' => 'Invalid query', + 'message' => $msg ]); $this->strErrorDesc = 'Unprocessable Query'; $this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Query';