mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 04:34:29 -06:00
Work on member attributes
This commit is contained in:
parent
ff77fa97af
commit
5481bb7698
102
Controller/API/AttributeController.php
Normal file
102
Controller/API/AttributeController.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Description of AttributeController
|
||||
*
|
||||
* @author Mike Howard
|
||||
*/
|
||||
class AttributeController extends BaseController {
|
||||
public $attributeModel;
|
||||
public $action;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->basename = "AttributeController";
|
||||
}
|
||||
|
||||
public function processAction() {
|
||||
$this->strErrorDesc = '';
|
||||
$this->strErrorHeader = '';
|
||||
|
||||
try {
|
||||
$this->requestMethod = $this->getServerRequestMethod();
|
||||
|
||||
switch($this->action) {
|
||||
case "select":
|
||||
$response = $this->selectAction();
|
||||
break;
|
||||
|
||||
case "insert":
|
||||
$response = $this->insertAttribute();
|
||||
break;
|
||||
|
||||
case "update":
|
||||
$response = $this->updateAttribute();
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
$response = $this->deleteAttribute();
|
||||
break;
|
||||
|
||||
default:
|
||||
$response = (object) ['Result' => 'Default'];
|
||||
$this->strErrorDesc = 'Controller Method not supported for processAction: ' . $this->action;
|
||||
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity';
|
||||
break;
|
||||
}
|
||||
|
||||
$responseData = json_encode($response);
|
||||
} catch (Error $e) {
|
||||
$this->strErrorDesc = $e->getMessage().' Something went wrong in processAction! Please contact support.';
|
||||
$this->strErrorHeader = 'HTTP/1.1 500 Internal Server Error';
|
||||
}
|
||||
|
||||
// send output
|
||||
if (!$this->strErrorDesc) {
|
||||
$this->sendOutput(
|
||||
$responseData,
|
||||
array('Content-Type: application/json', 'HTTP/1.1 200 OK')
|
||||
);
|
||||
} else {
|
||||
$this->sendOutput(json_encode(array('error' => $this->strErrorDesc)),
|
||||
array('Content-Type: application/json', $this->strErrorHeader)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function selectAction(){
|
||||
if ($this->checkRequestType('GET') == 'false') {
|
||||
$this->strErrorDesc = 'Request Method not supported for processAction';
|
||||
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request';
|
||||
return;
|
||||
}
|
||||
|
||||
$this->attributeModel = new AttributeModel();
|
||||
$this->arrQueryStringParams = $this->getQueryStringParams();
|
||||
|
||||
if (isset($this->arrQueryStringParams['loyalty_member_id'])) {
|
||||
$response = $this->selectByIdAction();
|
||||
} else {
|
||||
//$this->attributeModel->limit = 10;
|
||||
|
||||
if (isset($this->arrQueryStringParams['limit'])) {
|
||||
$this->attributeModel->limit = $this->arrQueryStringParams['limit'];
|
||||
}
|
||||
$response = $this->attributeModel->findAllAttributes();
|
||||
unset($this->attributeModel->limit);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function selectByIdAction(){
|
||||
if (isset($this->arrQueryStringParams['loyalty_member_id'])) {
|
||||
$this->attributeModel->attributeId = $this->arrQueryStringParams['loyalty_member_id'];
|
||||
$response = $this->attributeModel->findAttributesByMemberId();
|
||||
unset($this->attributeModel->attributeId);
|
||||
} else {
|
||||
return $this->notFoundResponse();
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
24
Model/AttributeModel.php
Normal file
24
Model/AttributeModel.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Description of AttributeModel
|
||||
*
|
||||
* @author Mike Howard
|
||||
*/
|
||||
|
||||
require_once PD . "/Model/Database.php";
|
||||
require_once PD . "/Model/ModelTraits.php";
|
||||
|
||||
class AttributeModel {
|
||||
use ModelTraits;
|
||||
|
||||
public function findAllAttributes()
|
||||
{
|
||||
return $this->processQuery("SELECT * FROM loyalty_attribute ORDER BY loyalty_attribute_id ASC LIMIT ?", ["i", $this->limit]);
|
||||
}
|
||||
|
||||
public function findAttributesByMemberId()
|
||||
{
|
||||
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ?", ["i", $this->memberId]);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
//define('PD', 'D:\DEV\Git Repository\CustomerRewardsRESTAPI');
|
||||
//require_once PROJECT_ROOT_PATH . "/Model/Database.php";
|
||||
require_once PD . "/Model/Database.php";
|
||||
require_once PD . "/Model/ModelTraits.php";
|
||||
|
||||
/**
|
||||
* Description of CustomerModel
|
||||
|
@ -27,6 +23,9 @@ require_once PD . "/Model/ModelTraits.php";
|
|||
* address_zip varchar(10)
|
||||
*/
|
||||
|
||||
require_once PD . "/Model/Database.php";
|
||||
require_once PD . "/Model/ModelTraits.php";
|
||||
|
||||
class CustomerModel extends Database {
|
||||
use ModelTraits;
|
||||
|
||||
|
|
|
@ -44,6 +44,11 @@ switch($uri[$uri_pos + 1]) {
|
|||
$objFeedController = new CustomerController();
|
||||
break;
|
||||
|
||||
case "attribute":
|
||||
require PROJECT_ROOT_PATH . "/Controller/Api/AttributeController.php";
|
||||
$objFeedController = new AttributeController();
|
||||
break;
|
||||
|
||||
case "image":
|
||||
require PROJECT_ROOT_PATH . "/Controller/Api/ImageController.php";
|
||||
$objFeedController = new ImageController();
|
||||
|
|
Loading…
Reference in New Issue
Block a user