Perbaikan API Posisi Rubrik
This commit is contained in:
@@ -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
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user