mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-10 05:44:29 -06:00
Work on attributes
This commit is contained in:
parent
3e20b57008
commit
c67b95240b
|
@ -105,7 +105,7 @@ class AttributeController extends BaseController {
|
||||||
}
|
}
|
||||||
$jsonPayload = file_get_contents('php://input');
|
$jsonPayload = file_get_contents('php://input');
|
||||||
$input = json_decode($jsonPayload, TRUE);
|
$input = json_decode($jsonPayload, TRUE);
|
||||||
|
|
||||||
if (! $this->validateAttribute($input)) {
|
if (! $this->validateAttribute($input)) {
|
||||||
return $this->unprocessableEntityResponse("validateAttribute");
|
return $this->unprocessableEntityResponse("validateAttribute");
|
||||||
}
|
}
|
||||||
|
@ -113,11 +113,12 @@ class AttributeController extends BaseController {
|
||||||
if ($input['LOYALTY_MEMBER_ID'] != null) {
|
if ($input['LOYALTY_MEMBER_ID'] != null) {
|
||||||
$this->attributeModel->memberId = $input['LOYALTY_MEMBER_ID'];
|
$this->attributeModel->memberId = $input['LOYALTY_MEMBER_ID'];
|
||||||
$this->attributeModel->attributeId = $input['LOYALTY_ATTRIBUTE_ID'];
|
$this->attributeModel->attributeId = $input['LOYALTY_ATTRIBUTE_ID'];
|
||||||
|
|
||||||
$result = $this->attributeModel->findMemberAttribute();
|
$result = $this->attributeModel->findMemberAttribute();
|
||||||
if (! $result) {
|
if (! $result) {
|
||||||
return $this->notFoundResponse("attributeModel->findMemberAttribute");
|
return $this->notFoundResponse("attributeModel->findMemberAttribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->attributeModel->updateMemberAttribute($input);
|
$response = $this->attributeModel->updateMemberAttribute($input);
|
||||||
unset($this->attributeModel->memberId);
|
unset($this->attributeModel->memberId);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,7 +24,10 @@ class AttributeModel extends Database {
|
||||||
|
|
||||||
public function findMemberAttribute()
|
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)
|
public function insertAttribute($inputModel)
|
||||||
|
@ -64,15 +67,21 @@ class AttributeModel extends Database {
|
||||||
"LOYALTY_VALUE": "http://localhost/CustomerRewardsRESTAPI/public/images/1.jpg"
|
"LOYALTY_VALUE": "http://localhost/CustomerRewardsRESTAPI/public/images/1.jpg"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$keys = array_keys($jsonPayLoad);
|
$keys = array_keys($jsonPayLoad);
|
||||||
$n = count($keys);
|
$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++) {
|
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]] . ")";
|
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
||||||
|
|
||||||
$rowCount = $this->processStatement($query);
|
$rowCount = $this->processStatement($query);
|
||||||
return $rowCount;
|
return $rowCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ class CustomerModel extends Database {
|
||||||
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
|
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
|
||||||
}
|
}
|
||||||
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
||||||
|
//return var_dump($query);
|
||||||
$rowCount = $this->processStatement($query);
|
$rowCount = $this->processStatement($query);
|
||||||
return $rowCount;
|
return $rowCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ class Database {
|
||||||
{
|
{
|
||||||
$response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Query';
|
$response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Query';
|
||||||
$response['body'] = json_encode([
|
$response['body'] = json_encode([
|
||||||
'error' => 'Invalid query'
|
'error' => 'Invalid query',
|
||||||
|
'message' => $msg
|
||||||
]);
|
]);
|
||||||
$this->strErrorDesc = 'Unprocessable Query';
|
$this->strErrorDesc = 'Unprocessable Query';
|
||||||
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Query';
|
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Query';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user