Skip to content
Snippets Groups Projects
Commit 5220b447 authored by Fawwaz Anugrah Wiradhika Dharmasatya's avatar Fawwaz Anugrah Wiradhika Dharmasatya
Browse files

Merge branch 'main' of gitlab.informatika.org:IF3110-2022-K02-02-05/tugas-besar-1-webtune-app

parents 80878978 e490ea58
Branches
Tags
No related merge requests found
......@@ -7,6 +7,9 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=root
API_KEY=secret
SOAP_HOST=http://webtune-soap:8080/webtune-soap
REST_HOST=http://webtune-rest:8888
REST_KEY=secret_turu
\ No newline at end of file
REST_API="http://webtune-rest:8888"
REST_KEY=secret_turu
SOAP_API=http://webtune-soap:8080/webtune-soap
SOAP_KEY=secret_blebekblebek
......@@ -147,9 +147,8 @@ class SubsciberController
}
}
static function fetchSubscriptions(int $page, int $limit, int $user_id, $db)
{
$fetcher = new FetchAPI(getenv("REST_HOST"));
static function fetchSubscriptions(int $page,int $limit, int $user_id,$db){
$fetcher = new FetchAPI(getenv("REST_API"));
$param = [
"page" => $page,
"limit" => $limit,
......@@ -220,7 +219,7 @@ class SubsciberController
// $data = json_decode($output,true)["data"];
//fetch max page
$fetcher = new FetchAPI(getenv("REST_HOST"));
$fetcher = new FetchAPI(getenv("REST_API"));
$param = [
"page-size" => $limit,
];
......
......@@ -4,11 +4,14 @@ namespace Controller;
use Lib\Interfaces\Routing\IRequest;
use Lib\Interfaces\Routing\IResponse;
use Service\Soap\TestSoap;
class ExampleController {
static function HalamanX(IRequest $req, IResponse $res) {
return $res->view("Pages/HalamanX", [
"kucing" => 12,
class TestController {
static function soapPing(IRequest $req, IResponse $res) {
$test = new TestSoap();
return $res->json([
"result" => $test->ping(),
]);
}
}
<?php
namespace Lib\Service\Api;
use PDO;
namespace Lib\Service\Api;
class FetchAPI{
private string $host;
class FetchAPI{
private string $host;
public function __construct(string $host)
{
$this->host = $host;
}
public function get(string $endpoint,array $param, array $headers){
$url = $this->host . $endpoint;
//add param
if(count($param)>0){
$url .= "?";
}
foreach($param as $key=>$value){
$url = $url . $key . "=" . $value . "&";
}
$ch = curl_init($url);
//set curl header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch , CURLOPT_TIMEOUT, 10000);
//set http header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close($ch);
public function __construct(string $host)
{
$this->host = $host;
}
return $output;
public function get(string $endpoint,array $param, array $headers){
$url = $this->host . $endpoint;
//add param
if(count($param)>0){
$url .= "?";
}
foreach($param as $key=>$value){
$url = $url . $key . "=" . $value . "&";
}
$ch = curl_init($url);
//set curl header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch , CURLOPT_TIMEOUT, 10000);
//set http header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close($ch);
public function post(string $endpoint,array $param, array $headers){
$url = $this->host . $endpoint;
//add param
$ch = curl_init($url);
//set curl header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch , CURLOPT_TIMEOUT, 10000);
//set post payload
curl_setopt($ch, CURLOPT_POST, 1);
$post_payload = "";
foreach($param as $key=>$value){
$post_payload = $post_payload . $key . "=" . $value . "&";
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_payload);
//set http header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
return $output;
public function post(string $endpoint,array $param, array $headers){
$url = $this->host . $endpoint;
//add param
$ch = curl_init($url);
//set curl header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch , CURLOPT_TIMEOUT, 10000);
//set post payload
curl_setopt($ch, CURLOPT_POST, 1);
$post_payload = "";
foreach($param as $key=>$value){
$post_payload = $post_payload . $key . "=" . $value . "&";
}
}
\ No newline at end of file
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_payload);
//set http header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ use Controller\AlbumController;
use Controller\HomeController;
use Controller\LaguController;
use Controller\SubsciberController;
use Controller\TestController;
use Lib\Dependency;
use Lib\Enums\Request\HttpMethod;
use Lib\Interfaces\Routing\IRoute;
......@@ -25,6 +26,7 @@ class AppRoutes
$route = $this->route;
$route->route(HttpMethod::Get, "/", [HomeController::class, "homepage"]);
$route->route(HttpMethod::Get, "/soap/ping", [TestController::class, "soapPing"]);
//halaman lihat lagu
$route->route(HttpMethod::Get, "/redirect/search", [LaguController::class, "redirectSearchLagu"]);
......@@ -39,7 +41,6 @@ class AppRoutes
// Auth
$route->groupRoute("/auth", AuthRoutes::getRoutes());
$route->route(HttpMethod::Get, "/testing", [ExampleController::class, "HalamanX"]);
// Album
$route->route(HttpMethod::Get, "/album", [AlbumController::class, "getAlbums"]);
......
<?php
namespace Service\Soap;
class TestSoap {
private SoapClientFactory $factory;
public function __construct() {
$wsdl = getenv("SOAP_API"). "/services/test?wsdl";
$this->factory = new SoapClientFactory($wsdl);
}
public function ping(
?string $last_token = null
): string {
$soap = $this->factory->generate_client($last_token);
return $soap->__soapCall(
"ping",
[]
);
}
}
\ No newline at end of file
......@@ -7,9 +7,6 @@ use SoapClient;
class TokenSoap {
private SoapClient $soap;
static string | null $token;
static int $exp_time;
public function __construct() {
$soap_key = getenv("SOAP_KEY");
$wsdl = getenv("SOAP_API")."/services/security?wsdl";
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment