Fix: perbaikan suplemen detail dan edit#1081
Merged
Merged
Conversation
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Fix Error Halaman Detail Suplemen dan Refactor ke Service Layer
Description
Fix error "Call to undefined function selected()" pada halaman edit suplemen serta refactor data access dari Eloquent model langsung ke
SuplemenServiceyang melakukan API request. Perubahan ini menyesuaikan field mapping antara API response (menggunakansasaranstring dansasaran_id/status_idnumeric) dengan template Blade yang sebelumnya mengharapkan format berbeda.Changes made:
app/Services/SuplemenService.php— Membuat service class baru yang mengakses data suplemen melalui API (/api/v1/suplemen) dengan caching, menggantikan Eloquent modelSuplemen::findOrFail().app/Http/Controllers/SuplemenController.php— Menggunakan dependency injectionSuplemenServicepada constructor, mengganti semua query Eloquent (Suplemen,SuplemenTerdata,Config,Wilayah) menjadi method call ke service.resources/views/suplemen/edit.blade.php— Menggantiselected()helper yang tidak ada dengan inline ternary operator, serta menyesuaikan field mapping ($suplemen->sasaran_id,$suplemen->status_id).resources/views/suplemen/cetak/table.blade.phpdanresources/views/suplemen/table_terdata.blade.php— Mengubah perbandingan numeric ($suplemen->sasaran == 1) menjadi string comparison ($suplemen->sasaran === 'Penduduk').resources/views/suplemen/cetak/data_suplemen.blade.phpdanresources/views/suplemen/rincian.blade.php— Menghapus array lookup$sasaran[$suplemen->sasaran]karena data sasaran sudah berupa string dari API.resources/views/suplemen/js/data_suplemen_terdata.blade.php— Mengubah$suplemen->sasaranmenjadi$suplemen->sasaran_iduntuk URL API terdata.resources/views/suplemen/preview_js.blade.php— Menyederhanakan logika preview sasaran dan status karena data sudah dalam format final dari API.Reason for change:
selected()bukan helper function bawaan Laravel, sehingga menyebabkan fatal error saat membuka halaman edit suplemen.sasaran(string seperti "Penduduk"/"Hamil") dansasaran_id(numeric), sedangkan template Blade sebelumnya menggunakan numericsasarandengan array lookup dari constantSASARAN.Impact of change:
✅ Bug Fix: Error "Call to undefined function selected()" pada halaman edit suplemen teratasi
✅ Data Consistency: Template Blade menggunakan format data yang sesuai dengan API response
✅ Maintainability: Akses data terpusat di
SuplemenService, memudahkan maintenance dan testing✅ Cache Strategy:
suplemenById()tidak menggunakan cache untuk data real-time, method lain tetap ter-cache✅ Export Fix: Data cetak/ekspor menggunakan format sasaran string yang benar
Related Issue
Steps to Reproduce
Before fix (problem):
edit.blade.php:65After fix (solution):
Testing on related features:
Checklist
Technical Details
Technical Explanation
Sebelum refactor,
SuplemenControllermengakses data langsung menggunakan Eloquent model:Setelah refactor, semua akses data melalui
SuplemenServiceyang melakukan API request:API mengembalikan data dengan format:
sasaran: string ("Penduduk", "Keluarga", dll)sasaran_id: numeric (1, 2, dll)status: string ("Aktif", "Tidak Aktif")status_id: numeric (1, 0)Template Blade disesuaikan untuk menggunakan field yang benar:
Field Mapping
"Penduduk"(string)$suplemen->sasaran == 1(numeric)$suplemen->sasaran === 'Penduduk'(string)1(numeric)$suplemen->sasaran(assumed numeric)$suplemen->sasaran_id(explicit)"Aktif"(string)selected(1, $suplemen->status)$suplemen->status_id == 11(numeric)$suplemen->status_idDependencies added
BaseApiServiceyang sudah ada)Testing
Manual Testing
Breaking Changes
None — Perubahan ini backward compatible. API response format sudah ada sebelumnya, hanya template Blade yang disesuaikan.
Migration Guide
Not required
References
app/Services/BaseApiService.php— Parent class untuk API serviceapp/Services/SuplemenService.php— Service baru untuk akses data suplemenDepedency
https://github.com/OpenSID/API-Database-Gabungan/pull/441
Video
simplescreenrecorder-2026-06-26_06.22.20.mp4
Additional notes: PR ini menggabungkan bug fix (
selected()error) dan refactor (Eloquent ke Service). Untuk reviewer, mohon pastikan field mappingsasaranvssasaran_iddanstatusvsstatus_idsudah sesuai dengan API response diOpenSID/API-Database-Gabungan.