mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 05:04:29 -06:00
54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
|
|
*/
|
|
|
|
/**
|
|
* Description of PurchaseController
|
|
*
|
|
* @author SCTN4
|
|
*/
|
|
class PurchaseController extends BaseController{
|
|
/**
|
|
* "/purchase/list" Endpoint - Get list of purchases
|
|
*/
|
|
public function listAction()
|
|
{
|
|
$strErrorDesc = '';
|
|
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
|
$arrQueryStringParams = $this->getQueryStringParams();
|
|
if (strtoupper($requestMethod) == 'GET') {
|
|
try {
|
|
$purchaseModel = new PurchaseModel();
|
|
$intLimit = 10;
|
|
$dtDate = date("M/d/yy");
|
|
if (isset($arrQueryStringParams['limit']) && $arrQueryStringParams['limit']) {
|
|
$intLimit = $arrQueryStringParams['limit'];
|
|
$dtDate = $arrQueryStringParams['date'];
|
|
}
|
|
$arrPurchases = $purchaseModel->getPurchases($dtDate, $intLimit);
|
|
$responseData = json_encode($arrPurchases);
|
|
} catch (Error $e) {
|
|
$strErrorDesc = $e->getMessage().'Something went wrong! Please contact support.';
|
|
$strErrorHeader = 'HTTP/1.1 500 Internal Server Error';
|
|
}
|
|
} else {
|
|
$strErrorDesc = 'Method not supported';
|
|
$strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity';
|
|
}
|
|
// send output
|
|
if (!$strErrorDesc) {
|
|
$this->sendOutput(
|
|
$responseData,
|
|
array('Content-Type: application/json', 'HTTP/1.1 200 OK')
|
|
);
|
|
} else {
|
|
$this->sendOutput(json_encode(array('error' => $strErrorDesc)),
|
|
array('Content-Type: application/json', $strErrorHeader)
|
|
);
|
|
}
|
|
}
|
|
}
|