From 9e287d85d09cf24ab5263108756b3c1dbfc422ad Mon Sep 17 00:00:00 2001 From: unknown <13521043@std.stei.itb.ac.id> Date: Fri, 17 Nov 2023 10:53:19 +0700 Subject: [PATCH] create ApplicationController and the api --- src/api/application/index.php | 10 ++++ src/controller/ApplicationController.php | 73 ++++++++++++++++++++++++ src/public/javascript/gym/application.js | 16 ++++++ 3 files changed, 99 insertions(+) create mode 100644 src/api/application/index.php create mode 100644 src/controller/ApplicationController.php diff --git a/src/api/application/index.php b/src/api/application/index.php new file mode 100644 index 0000000..768686b --- /dev/null +++ b/src/api/application/index.php @@ -0,0 +1,10 @@ +<?php + +require_once __DIR__ . "/../../controller/ApplicationController.php"; +require_once __DIR__ . "/../../controller/ControllerWrapper.php"; + +$controller = new ApplicationController(); +$wrapper = new ControllerWrapper($controller); + +$wrapper->respond(); +?> \ No newline at end of file diff --git a/src/controller/ApplicationController.php b/src/controller/ApplicationController.php new file mode 100644 index 0000000..60063e1 --- /dev/null +++ b/src/controller/ApplicationController.php @@ -0,0 +1,73 @@ +<?php + +require __DIR__ . "/../inc/bootstrap.php"; +require_once PROJECT_ROOT_PATH . "/controller/BaseController.php"; +require_once PROJECT_ROOT_PATH . "/services/GymService.php"; + + +class ApplicationController extends BaseController +{ + + public function respond($requestMethod, &$responseData, &$strErrorDesc, &$strErrorHeader) + { + + $arrQueryStringParams = $this->getQueryStringParams(); + + switch ($requestMethod) { + case 'GET': + $id = $arrQueryStringParams['id']; + if (isset($id)) { + $soapurl = "http://localhost:3001/ws/application"; + $soapkey = "sabuntuhbuatmandibukanbuatwebservice_php"; + $gymId = $id; + + $soapBody = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + <Body> + <getAllAplication xmlns="http://service.gymtracker.com/"> + <gym_id xmlns="">37</gym_id> + </getAllAplication> + </Body> + </Envelope>'; + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: text/xml', + 'Authorization: ' . $soapkey + )); + curl_setopt($ch, CURLOPT_URL, $soapurl); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // give timeout of 10 seconds + + $response = curl_exec($ch); + + if (curl_errno($ch)) { + echo 'Curl error: ' . curl_error($ch); + } + + curl_close($ch); + + // Handle the response + if ($response) { + // return $response; + // $xml = simplexml_load_string($response, "SimpleXMLElement", LIBXML_NOCDATA); + // $json = json_encode($xml); + // $array = json_decode($json, TRUE); + // $responseData = $array['Body']['getAllAplicationResponse']['return']; + $responseData = $response; + } else { + $responseData = []; + } + + } + break; + + default: + $strErrorDesc = 'Method not supported'; + $strErrorHeader = 'HTTP/1.1 400 Bad Request'; + break; + } + } +} \ No newline at end of file diff --git a/src/public/javascript/gym/application.js b/src/public/javascript/gym/application.js index ea496dc..a4dc01a 100644 --- a/src/public/javascript/gym/application.js +++ b/src/public/javascript/gym/application.js @@ -49,6 +49,22 @@ function getGymApplication(gymId) { xhr.setRequestHeader("Content-Type", "text/xml"); xhr.setRequestHeader("Authorization", soapkey); xhr.send(soapBody); + // const xhr = new XMLHttpRequest(); + // xhr.onreadystatechange = function () { + // if (this.readyState === 4) { + // if (this.status === 200) { + // alert("application : " + this.responseText); + // // modifyGymRateList(JSON.parse(this.responseText)["ratings"], username); + // } else { + // const json = JSON.parse(this.responseText); + // alert(json["error"]); + // } + // } + // }; + + // xhr.open("GET", `/api/application?id=${gymId}`, true); + // xhr.setRequestHeader("X-API-KEY", apikey); + // xhr.send(); } function getApplication(username, gymId) { -- GitLab