mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-10 00:04:28 -06:00
Work on attributes
This commit is contained in:
parent
9320b25027
commit
3e20b57008
|
@ -32,15 +32,15 @@ class AttributeController extends BaseController {
|
|||
break;
|
||||
|
||||
case "insert":
|
||||
$response = $this->insertAttribute();
|
||||
$response = $this->insertMemberAttribute();
|
||||
break;
|
||||
|
||||
case "update":
|
||||
$response = $this->updateAttribute();
|
||||
$response = $this->updateMemberAttribute();
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
$response = $this->deleteAttribute();
|
||||
$response = $this->deleteMemberAttribute();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -97,4 +97,62 @@ class AttributeController extends BaseController {
|
|||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function updateMemberAttribute(){
|
||||
if ($this->checkRequestType('PUT') == 'false') {
|
||||
$response = $this->unprocessableRequestResponse("updateMemberAttribute");
|
||||
return $response;
|
||||
}
|
||||
$jsonPayload = file_get_contents('php://input');
|
||||
$input = json_decode($jsonPayload, TRUE);
|
||||
|
||||
if (! $this->validateAttribute($input)) {
|
||||
return $this->unprocessableEntityResponse("validateAttribute");
|
||||
}
|
||||
|
||||
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 {
|
||||
return $this->notFoundResponse("attributeModel->LOYALTY_MEMBER_ID");
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function insertMemberAttribute(){
|
||||
if ($this->checkRequestType('POST') == 'false') {
|
||||
$response = $this->unprocessableRequestResponse("insertMemberAttribute");
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->unprocessableRequestResponse("insertMemberAttribute Not Implemented");
|
||||
}
|
||||
|
||||
private function deleteMemberAttribute(){
|
||||
if ($this->checkRequestType('DELETE') == 'false') {
|
||||
$response = $this->unprocessableRequestResponse("deleteMemberAttribute");
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->unprocessableRequestResponse("deleteMemberAttribute Not Implemented");
|
||||
}
|
||||
|
||||
private function validateAttribute($input)
|
||||
{
|
||||
$validtion = false;
|
||||
if($input['LOYALTY_MEMBER_ID'] != null){
|
||||
$validtion = true;
|
||||
if($input['LOYALTY_ATTRIBUTE_ID'] == null) {
|
||||
$validtion = false;
|
||||
}
|
||||
}
|
||||
return $validtion;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ class BaseController {
|
|||
|
||||
public function __construct() {
|
||||
$this->basename = 'BaseController';
|
||||
$this->strErrorDesc = '';
|
||||
$this->strErrorHeader = '';
|
||||
$this->strErrorMessage = '';
|
||||
}
|
||||
|
||||
public static function create() { return new self(); }
|
||||
|
|
|
@ -122,7 +122,7 @@ class CustomerController extends BaseController {
|
|||
return $this->unprocessableEntityResponse();
|
||||
}
|
||||
|
||||
//remove customer_id field so it doesn't break
|
||||
//remove model fields so it doesn't break
|
||||
unset($input['customer_id']);
|
||||
unset($input['image_path']);
|
||||
|
||||
|
@ -150,6 +150,9 @@ class CustomerController extends BaseController {
|
|||
return $this->notFoundResponse("updateCustomer->findByCustomerId");
|
||||
}
|
||||
|
||||
//remove model fields so it doesn't break
|
||||
unset($input['image_path']);
|
||||
|
||||
$response = $this->customerModel->updateCustomer($input);
|
||||
unset($this->customerModel->customerId);
|
||||
} else {
|
||||
|
|
|
@ -21,4 +21,60 @@ class AttributeModel extends Database {
|
|||
{
|
||||
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ?", ["i", $this->memberId]);
|
||||
}
|
||||
|
||||
public function findMemberAttribute()
|
||||
{
|
||||
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ? AND loyalty_attribute_id = ?", ["ii", $this->memberId, $this->attributeId]);
|
||||
}
|
||||
|
||||
public function insertAttribute($inputModel)
|
||||
{
|
||||
/*
|
||||
{
|
||||
"loyalty_attribute_id": 6,
|
||||
"loyalty_attribute_name": "image_path",
|
||||
"loyalty_attribute_type_id": 4
|
||||
}
|
||||
*/
|
||||
//return var_dump($inputModel);
|
||||
$keys = array_keys($inputModel);
|
||||
$n = count($keys);
|
||||
|
||||
$query = "CALL insert_new_customer_proc (";
|
||||
for($i = 0; $i < $n-1; $i++) {
|
||||
$query .= "'" . $inputModel[$keys[$i]] . "', ";
|
||||
}
|
||||
$query .= $inputModel[$keys[$i]] . ")";
|
||||
//return var_dump($query);
|
||||
|
||||
$rowCount = $this->processStatement($query);
|
||||
return $rowCount;
|
||||
}
|
||||
|
||||
public function updateMemberAttribute($jsonPayLoad)
|
||||
{
|
||||
/*
|
||||
{
|
||||
"LOYALTY_MEMBER_ID": 1,
|
||||
"FIRST_NAME": "Mike",
|
||||
"LAST_NAME": "Howard",
|
||||
"LOYALTY_ATTRIBUTE_ID": 6,
|
||||
"LOYALTY_ITEM": "image_path",
|
||||
"LOYALTY_TYPE": "varchar",
|
||||
"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]] . ", ";
|
||||
for($i = 1; $i < $n-1; $i++) {
|
||||
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
|
||||
}
|
||||
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
||||
|
||||
$rowCount = $this->processStatement($query);
|
||||
return $rowCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class CustomerModel extends Database {
|
|||
$keys = array_keys($inputModel);
|
||||
$n = count($keys);
|
||||
|
||||
$query .= "CALL insert_new_customer_proc (";
|
||||
$query = "CALL insert_new_customer_proc (";
|
||||
for($i = 0; $i < $n-1; $i++) {
|
||||
$query .= "'" . $inputModel[$keys[$i]] . "', ";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user