Files
verifikator/app/Services/AktivitasService.php
T
2026-08-07 10:47:09 +07:00

79 lines
1.9 KiB
PHP

<?php
namespace App\Services;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use Throwable;
class AktivitasService
{
private $client;
public function __construct(string $default = 'http://172.16.40.177:8023/')
{
$this->client = new Client([
'base_uri' => $default,
'timeout' => 30,
'connect_timeout' => 10,
]);
}
public function getPengajuanSk()
{
try {
$response = $this->client->get('api/pengajuan-sk');
} catch (Throwable $th) {
Log::error('Aktivitas Pelayanan Service : '.$th->getMessage());
return false;
}
$data = json_decode($response->getBody()->getContents(), true);
return $data;
}
public function verifikasiPengajuan($id, $status, $catatan = null)
{
try {
// Jika status dibatalkan dari frontend, kirim sebagai diajukan ke API
$apiStatus = $status === 'dibatalkan' ? 'diajukan' : $status;
$payload = [
'status' => $apiStatus,
];
if ($catatan) {
$payload['keterangan'] = $catatan;
}
$response = $this->client->post("api/pengajuan-sk/{$id}/verifikasi", [
'json' => $payload,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
]);
$statusCode = $response->getStatusCode();
$body = $response->getBody()->getContents();
} catch (Throwable $th) {
Log::error('Aktivitas Pelayanan Service Verifikasi : '.$th->getMessage());
return false;
}
$data = json_decode($body, true);
if (json_last_error() !== JSON_ERROR_NONE) {
Log::error('JSON decode error: '.json_last_error_msg());
return false;
}
return $data;
}
}