Perbaikan API Posisi Rubrik
This commit is contained in:
@@ -7,7 +7,6 @@ use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
@@ -287,35 +286,24 @@ class SiskaService
|
||||
public function getPosisi(): array
|
||||
{
|
||||
return Cache::remember('siska_posisi', 3600, function () {
|
||||
try {
|
||||
$response = Http::get('http://172.16.40.201:9098/api/v1/siska3/');
|
||||
|
||||
return json_decode($response->getBody()->getContents(), true) ?? [];
|
||||
} catch (Throwable $th) {
|
||||
return [];
|
||||
}
|
||||
return app(ImamAVService::class)->getPosisiSiska() ?? [];
|
||||
});
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
$rawData = Cache::remember($cacheKey, 3600, function () use ($posisi, $isPembimbingPenguji) {
|
||||
try {
|
||||
$uri = $isPembimbingPenguji
|
||||
? 'http://172.16.40.201:9098/api/v1/sks'
|
||||
: "http://172.16.40.201:9098/api/v1/siska1/$posisi";
|
||||
$imamAV = app(ImamAVService::class);
|
||||
|
||||
$response = Http::get($uri);
|
||||
|
||||
return json_decode($response->getBody()->getContents(), true) ?? [];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return [];
|
||||
}
|
||||
return ($isPembimbingPenguji
|
||||
? $imamAV->getRubrikSks()
|
||||
: $imamAV->getRubrikByPosisi($posisi)) ?? [];
|
||||
});
|
||||
|
||||
$kategoris = collect($rawData)
|
||||
@@ -348,18 +336,7 @@ class SiskaService
|
||||
|
||||
public function getRubriksByKategoriId(int $kategori_id): ?array
|
||||
{
|
||||
try {
|
||||
$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;
|
||||
return app(ImamAVService::class)->getRubrikByKategori($kategori_id);
|
||||
}
|
||||
|
||||
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