Work on attributes

This commit is contained in:
sctn4elk 2024-06-02 20:09:40 -05:00
parent 9320b25027
commit 3e20b57008
5 changed files with 125 additions and 5 deletions

View File

@ -32,15 +32,15 @@ class AttributeController extends BaseController {
break; break;
case "insert": case "insert":
$response = $this->insertAttribute(); $response = $this->insertMemberAttribute();
break; break;
case "update": case "update":
$response = $this->updateAttribute(); $response = $this->updateMemberAttribute();
break; break;
case "delete": case "delete":
$response = $this->deleteAttribute(); $response = $this->deleteMemberAttribute();
break; break;
default: default:
@ -97,4 +97,62 @@ class AttributeController extends BaseController {
return $response; 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;
}
} }

View File

@ -15,6 +15,9 @@ class BaseController {
public function __construct() { public function __construct() {
$this->basename = 'BaseController'; $this->basename = 'BaseController';
$this->strErrorDesc = '';
$this->strErrorHeader = '';
$this->strErrorMessage = '';
} }
public static function create() { return new self(); } public static function create() { return new self(); }

View File

@ -122,7 +122,7 @@ class CustomerController extends BaseController {
return $this->unprocessableEntityResponse(); 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['customer_id']);
unset($input['image_path']); unset($input['image_path']);
@ -150,6 +150,9 @@ class CustomerController extends BaseController {
return $this->notFoundResponse("updateCustomer->findByCustomerId"); return $this->notFoundResponse("updateCustomer->findByCustomerId");
} }
//remove model fields so it doesn't break
unset($input['image_path']);
$response = $this->customerModel->updateCustomer($input); $response = $this->customerModel->updateCustomer($input);
unset($this->customerModel->customerId); unset($this->customerModel->customerId);
} else { } else {

View File

@ -21,4 +21,60 @@ class AttributeModel extends Database {
{ {
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ?", ["i", $this->memberId]); 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;
}
} }

View File

@ -48,7 +48,7 @@ class CustomerModel extends Database {
$keys = array_keys($inputModel); $keys = array_keys($inputModel);
$n = count($keys); $n = count($keys);
$query .= "CALL insert_new_customer_proc ("; $query = "CALL insert_new_customer_proc (";
for($i = 0; $i < $n-1; $i++) { for($i = 0; $i < $n-1; $i++) {
$query .= "'" . $inputModel[$keys[$i]] . "', "; $query .= "'" . $inputModel[$keys[$i]] . "', ";
} }