add value host email and password from db global settings table

This commit is contained in:
arifal
2025-01-27 19:46:45 +07:00
parent 82ab44cfb6
commit 8b77e748ca
7 changed files with 103 additions and 17 deletions

View File

@@ -17,7 +17,7 @@ class GlobalSettingsController extends Controller
*/ */
public function index() public function index()
{ {
$query = GlobalSetting::query(); $query = GlobalSetting::query()->orderBy('id','desc');
return GlobalSettingResource::collection($query->paginate()); return GlobalSettingResource::collection($query->paginate());
} }

View File

@@ -14,13 +14,13 @@ class ImportDatasourceController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$query = ImportDatasource::query(); $query = ImportDatasource::query()->orderBy('id', 'desc');
if($request->has("search") && !empty($request->get("search"))){ if($request->has("search") && !empty($request->get("search"))){
$search = $request->get("search"); $search = $request->get("search");
$query->where('status', 'like', "%".$search."%"); $query->where('status', 'like', "%".$search."%");
} }
return ImportDatasourceResource::collection($query->paginate()->withQueryString()); return ImportDatasourceResource::collection($query->paginate(10));
} }
/** /**

View File

@@ -19,7 +19,9 @@ class GlobalSettingResource extends JsonResource
'key' => $this->key, 'key' => $this->key,
'value' => $this->value, 'value' => $this->value,
'type' => $this->type, 'type' => $this->type,
'description' => $this->description 'description' => $this->description,
'created_at' => $this->created_at->toDateTimeString(),
'updated_at' => $this->updated_at->toDateTimeString(),
]; ];
} }
} }

View File

@@ -3,6 +3,7 @@
namespace App; namespace App;
use App\Enums\ImportDatasourceStatus; use App\Enums\ImportDatasourceStatus;
use App\Models\GlobalSetting;
use App\Models\ImportDatasource; use App\Models\ImportDatasource;
use App\Models\PbgTaskIndexIntegrations; use App\Models\PbgTaskIndexIntegrations;
use App\Models\PbgTaskPrasarana; use App\Models\PbgTaskPrasarana;
@@ -17,18 +18,20 @@ class ServiceSIMBG
use GlobalApiResponse; use GlobalApiResponse;
private $email; private $email;
private $password; private $password;
private $simbg_host;
/** /**
* Create a new class instance. * Create a new class instance.
*/ */
public function __construct() public function __construct()
{ {
$this->email = $_ENV['SIMBG_EMAIL']; $this->email = trim((string) GlobalSetting::where('key','SIMBG_EMAIL')->first()->value);
$this->password = $_ENV['SIMBG_PASSWORD']; $this->password = trim((string) GlobalSetting::where('key','SIMBG_PASSWORD')->first()->value);
$this->simbg_host = trim((string)GlobalSetting::where('key','SIMBG_HOST')->first()->value);
} }
public function getToken(){ public function getToken(){
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']); $clientHelper = new ServiceClient($this->simbg_host);
$url = "api/user/v1/auth/login/"; $url = "/api/user/v1/auth/login/";
$body = [ $body = [
'email' => $this->email, 'email' => $this->email,
'password' => $this->password, 'password' => $this->password,
@@ -44,8 +47,8 @@ class ServiceSIMBG
public function syncIndexIntegration($uuid) public function syncIndexIntegration($uuid)
{ {
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']); $clientHelper = new ServiceClient($this->simbg_host);
$url = "api/pbg/v1/detail/" . $uuid . "/retribution/indeks-terintegrasi/"; $url = "/api/pbg/v1/detail/" . $uuid . "/retribution/indeks-terintegrasi/";
$resToken = $this->getToken(); $resToken = $this->getToken();
if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) { if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) {
@@ -93,7 +96,7 @@ class ServiceSIMBG
public function syncTaskList() public function syncTaskList()
{ {
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']); $clientHelper = new ServiceClient($this->simbg_host);
$resToken = $this->getToken(); $resToken = $this->getToken();
// create log import datasource // create log import datasource
@@ -118,7 +121,7 @@ class ServiceSIMBG
'type' => 'task', 'type' => 'task',
]); ]);
$url = "api/pbg/v1/list/?" . $queryParams; $url = "/api/pbg/v1/list/?" . $queryParams;
$headers = ['Authorization' => "Bearer " . $apiToken]; $headers = ['Authorization' => "Bearer " . $apiToken];
$initialResponse = $clientHelper->get($url, $headers); $initialResponse = $clientHelper->get($url, $headers);
@@ -143,7 +146,7 @@ class ServiceSIMBG
'type' => 'task', 'type' => 'task',
]); ]);
$url = "api/pbg/v1/list/?" . $queryParams; $url = "/api/pbg/v1/list/?" . $queryParams;
$response = $clientHelper->get($url, $headers); $response = $clientHelper->get($url, $headers);
if (empty($response->original['data']['data'])) { if (empty($response->original['data']['data'])) {
@@ -221,7 +224,7 @@ class ServiceSIMBG
public function syncTaskDetailSubmit($uuid) public function syncTaskDetailSubmit($uuid)
{ {
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']); $clientHelper = new ServiceClient($this->simbg_host);
$resToken = $this->getToken(); $resToken = $this->getToken();
if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) { if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) {
@@ -231,7 +234,7 @@ class ServiceSIMBG
} }
$apiToken = $resToken->original['data']['token']['access']; $apiToken = $resToken->original['data']['token']['access'];
$url = "api/pbg/v1/detail/" . $uuid . "/retribution/submit/"; $url = "/api/pbg/v1/detail/" . $uuid . "/retribution/submit/";
$headers = [ $headers = [
'Authorization' => "Bearer " . $apiToken, 'Authorization' => "Bearer " . $apiToken,
]; ];

View File

@@ -0,0 +1,45 @@
<?php
namespace Database\Seeders;
use App\Models\GlobalSetting;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class GlobalSettingSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$globalSettings = [
[
"key" => "SIMBG_HOST",
"value" => "https://simbg.pu.go.id",
"type" => "string",
"description" => "Host SIMBG",
"created_at" => Carbon::now()->format("Y-m-d H:i:s"),
"updated_at" => Carbon::now()->format("Y-m-d H:i:s"),
],
[
"key" => "SIMBG_PASSWORD",
"value" => "Simbg123",
"type" => "string",
"description" => "Password SIMBG",
"created_at" => Carbon::now()->format("Y-m-d H:i:s"),
"updated_at" => Carbon::now()->format("Y-m-d H:i:s"),
],
[
"key" => "SIMBG_EMAIL",
"value" => "dputr@bandungkab.go.id",
"type" => "string",
"description" => "Email SIMBG",
"created_at" => Carbon::now()->format("Y-m-d H:i:s"),
"updated_at" => Carbon::now()->format("Y-m-d H:i:s"),
],
];
GlobalSetting::insert($globalSettings);
}
}

View File

@@ -0,0 +1,36 @@
import { Grid } from "gridjs/dist/gridjs.umd.js";
import gridjs from 'gridjs/dist/gridjs.umd.js'
import 'gridjs/dist/gridjs.umd.js'
import GlobalConfig from "../../global-config.js";
class SyncronizeTask {
init(){
this.initTableGeneralSettings();
}
initTableGeneralSettings(){
new Grid({
columns: [
"ID", "Key", "Value", "Description", "Created",
],
pagination: {
limit: 10,
server: {
url: (prev, page, limit) => `${prev}?page=${page}`
}
},
sort: true,
search: {
server: {
url: (prev, page, keyword) => `${prev}?page=${page}&search=${keyword}`
}
},
server: {
url: `${GlobalConfig.apiHost}/api/global-settings`,
then: data => data.data.map((item) => [item.id, item.key, item.value, item.description, item.created_at])
}
}).render(document.getElementById("general-setting-table"));
}
}
document.addEventListener('DOMContentLoaded', function (e) {
new SyncronizeTask().init();
});

View File

@@ -13,12 +13,12 @@
<button type="button" class="btn btn-outline-success width-lg">Create</button> <button type="button" class="btn btn-outline-success width-lg">Create</button>
</div> </div>
<div> <div>
<div id="common-table"></div> <div id="general-setting-table"></div>
</div> </div>
</div> </div>
@endsection @endsection
@section('scripts') @section('scripts')
@vite(['resources/js/tables/common-table.js']) @vite(['resources/js/settings/general/general-settings.js'])
@endsection @endsection