Perbaikan API Posisi Rubrik #116
@@ -695,6 +695,92 @@ class ImamAVService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET terautentikasi dengan retry sekali saat token kedaluwarsa (401).
|
||||||
|
* Mengembalikan hasil decode JSON, atau null jika gagal.
|
||||||
|
*/
|
||||||
|
private function authorizedGet(string $path): ?array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$token = $this->getBearerToken();
|
||||||
|
|
||||||
|
if (! $token) {
|
||||||
|
Log::error("ImamAV GET {$path}: gagal autentikasi");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->client->get($path, [
|
||||||
|
'headers' => ['Authorization' => 'Bearer '.$token],
|
||||||
|
'http_errors' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() === 401) {
|
||||||
|
Cache::forget('imamav_token');
|
||||||
|
$newToken = $this->login();
|
||||||
|
|
||||||
|
if (! $newToken) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->client->get($path, [
|
||||||
|
'headers' => ['Authorization' => 'Bearer '.$newToken],
|
||||||
|
'http_errors' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response->getStatusCode() !== 200) {
|
||||||
|
Log::error("ImamAV GET {$path} gagal. Status: ".$response->getStatusCode());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
|
|
||||||
|
return is_array($data) ? $data : null;
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error("ImamAV GET {$path} error: ".$th->getMessage());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Daftar posisi (kompatibel API lama /api/v1/posisi). */
|
||||||
|
public function getPosisiLama(): ?array
|
||||||
|
{
|
||||||
|
return $this->authorizedGet('api/v1/posisi');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Daftar posisi (kompatibel API lama /api/v1/posisis). */
|
||||||
|
public function getPosisis(): ?array
|
||||||
|
{
|
||||||
|
return $this->authorizedGet('api/v1/posisis');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rubrik berdasarkan posisi (kompatibel API lama /api/v1/siska1/{posisi}). */
|
||||||
|
public function getRubrikByPosisi(string $posisi): ?array
|
||||||
|
{
|
||||||
|
return $this->authorizedGet('api/v1/siska1/'.rawurlencode($posisi));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rubrik berdasarkan kategori (kompatibel API lama /api/v1/siska2/{idkategori}). */
|
||||||
|
public function getRubrikByKategori(int $idKategori): ?array
|
||||||
|
{
|
||||||
|
return $this->authorizedGet("api/v1/siska2/{$idKategori}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Daftar posisi SISKA (kompatibel API lama /api/v1/siska3). */
|
||||||
|
public function getPosisiSiska(): ?array
|
||||||
|
{
|
||||||
|
return $this->authorizedGet('api/v1/siska3');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rubrik pembimbing/penguji (API lama /api/v1/sks). */
|
||||||
|
public function getRubrikSks(): ?array
|
||||||
|
{
|
||||||
|
return $this->authorizedGet('api/v1/sks');
|
||||||
|
}
|
||||||
|
|
||||||
public function attendanceSimulasi2026(string $nip, array $params = []): array
|
public function attendanceSimulasi2026(string $nip, array $params = []): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use GuzzleHttp\Client;
|
|||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use GuzzleHttp\Exception\ServerException;
|
use GuzzleHttp\Exception\ServerException;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
@@ -287,35 +286,24 @@ class SiskaService
|
|||||||
public function getPosisi(): array
|
public function getPosisi(): array
|
||||||
{
|
{
|
||||||
return Cache::remember('siska_posisi', 3600, function () {
|
return Cache::remember('siska_posisi', 3600, function () {
|
||||||
try {
|
return app(ImamAVService::class)->getPosisiSiska() ?? [];
|
||||||
$response = Http::get('http://172.16.40.201:9098/api/v1/siska3/');
|
|
||||||
|
|
||||||
return json_decode($response->getBody()->getContents(), true) ?? [];
|
|
||||||
} catch (Throwable $th) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getKategoriByPosisi(string $posisi, array $exclude = []): ?array
|
public function getKategoriByPosisi(string $posisi, array $exclude = []): ?array
|
||||||
{
|
{
|
||||||
$isPembimbingPenguji = str_contains(strtolower($posisi), 'pembimbing') || str_contains(strtolower($posisi), 'penguji');
|
// Posisi ber-"/" tidak bisa dipanggil lewat /api/v1/siska1/{posisi} (server 404), tetapi ada di /api/v1/sks
|
||||||
|
$isPembimbingPenguji = str_contains(strtolower($posisi), 'pembimbing')
|
||||||
|
|| str_contains(strtolower($posisi), 'penguji')
|
||||||
|
|| str_contains($posisi, '/');
|
||||||
$cacheKey = $isPembimbingPenguji ? 'siska_kategori_sks' : 'siska_kategori_'.md5(strtolower($posisi));
|
$cacheKey = $isPembimbingPenguji ? 'siska_kategori_sks' : 'siska_kategori_'.md5(strtolower($posisi));
|
||||||
|
|
||||||
$rawData = Cache::remember($cacheKey, 3600, function () use ($posisi, $isPembimbingPenguji) {
|
$rawData = Cache::remember($cacheKey, 3600, function () use ($posisi, $isPembimbingPenguji) {
|
||||||
try {
|
$imamAV = app(ImamAVService::class);
|
||||||
$uri = $isPembimbingPenguji
|
|
||||||
? 'http://172.16.40.201:9098/api/v1/sks'
|
|
||||||
: "http://172.16.40.201:9098/api/v1/siska1/$posisi";
|
|
||||||
|
|
||||||
$response = Http::get($uri);
|
return ($isPembimbingPenguji
|
||||||
|
? $imamAV->getRubrikSks()
|
||||||
return json_decode($response->getBody()->getContents(), true) ?? [];
|
: $imamAV->getRubrikByPosisi($posisi)) ?? [];
|
||||||
} catch (Throwable $th) {
|
|
||||||
Log::error('SISKA : '.$th->getMessage());
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$kategoris = collect($rawData)
|
$kategoris = collect($rawData)
|
||||||
@@ -348,18 +336,7 @@ class SiskaService
|
|||||||
|
|
||||||
public function getRubriksByKategoriId(int $kategori_id): ?array
|
public function getRubriksByKategoriId(int $kategori_id): ?array
|
||||||
{
|
{
|
||||||
try {
|
return app(ImamAVService::class)->getRubrikByKategori($kategori_id);
|
||||||
$uri = "http://172.16.40.201:9098/api/v1/siska2/$kategori_id";
|
|
||||||
|
|
||||||
$response = Http::get($uri);
|
|
||||||
$rubriks = json_decode($response->getBody()->getContents(), true);
|
|
||||||
} catch (Throwable $th) {
|
|
||||||
Log::error('SISKA: '.$th->getMessage());
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rubriks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchSks(string $keyword, string $status = 'belum-verif', int $page = 1, int $per_page = 10, ?int $id_unit = null): ?array
|
public function searchSks(string $keyword, string $status = 'belum-verif', int $page = 1, int $per_page = 10, ?int $id_unit = null): ?array
|
||||||
|
|||||||
Reference in New Issue
Block a user