feat: endpoint kelas (wali kelas dari kesiswaan + teman sekelas) + koneksi DB kesiswaan
This commit is contained in:
@@ -42,3 +42,10 @@ DB_EJURNAL_PORT=3306
|
|||||||
DB_EJURNAL_DATABASE=e_jurnal
|
DB_EJURNAL_DATABASE=e_jurnal
|
||||||
DB_EJURNAL_USERNAME=ejurnal
|
DB_EJURNAL_USERNAME=ejurnal
|
||||||
DB_EJURNAL_PASSWORD=P4ssw0rd
|
DB_EJURNAL_PASSWORD=P4ssw0rd
|
||||||
|
|
||||||
|
# ===== Koneksi database kesiswaan (wali kelas & data siswa) =====
|
||||||
|
DB_KESISWAAN_HOST=127.0.0.1
|
||||||
|
DB_KESISWAAN_PORT=3306
|
||||||
|
DB_KESISWAAN_DATABASE=database_kesiswaan
|
||||||
|
DB_KESISWAAN_USERNAME=kesiswaan
|
||||||
|
DB_KESISWAAN_PASSWORD=P4ssw0rd
|
||||||
|
|||||||
@@ -405,6 +405,51 @@ class ParentStudentController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daftar teman sekelas + wali kelas putra/putri.
|
||||||
|
*/
|
||||||
|
public function classmates(Request $request, Student $student): JsonResponse
|
||||||
|
{
|
||||||
|
$hasLink = ParentStudent::where('user_id', $request->user()->id)
|
||||||
|
->where('student_id', $student->id)
|
||||||
|
->where('status', 'active')
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
abort_unless($hasLink, 403, 'Putra/putri belum tertaut aktif.');
|
||||||
|
|
||||||
|
// Wali kelas dari database kesiswaan
|
||||||
|
$homeroom = null;
|
||||||
|
try {
|
||||||
|
$homeroom = DB::connection('kesiswaan')
|
||||||
|
->table('classes')
|
||||||
|
->where('name', $student->class_name)
|
||||||
|
->where('is_active', 1)
|
||||||
|
->orderByDesc('id')
|
||||||
|
->value('homeroom_teacher');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Wali kelas tidak tersedia: '.$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Teman sekelas dari tabel students (aktif)
|
||||||
|
$students = Student::where('class_name', $student->class_name)
|
||||||
|
->where('is_active', true)
|
||||||
|
->orderBy('full_name')
|
||||||
|
->get(['id', 'full_name', 'gender'])
|
||||||
|
->map(fn (Student $s) => [
|
||||||
|
'id' => $s->id,
|
||||||
|
'name' => $s->full_name,
|
||||||
|
'gender' => $s->gender, // L | P
|
||||||
|
])
|
||||||
|
->values();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'class_name' => $student->class_name,
|
||||||
|
'homeroom_teacher' => $homeroom,
|
||||||
|
'students' => $students,
|
||||||
|
'total' => $students->count(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tautkan anak tambahan (kakak/adik) ke akun wali.
|
* Tautkan anak tambahan (kakak/adik) ke akun wali.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -78,6 +78,20 @@ return [
|
|||||||
'engine' => null,
|
'engine' => null,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'kesiswaan' => [
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => env('DB_KESISWAAN_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('DB_KESISWAAN_PORT', '3306'),
|
||||||
|
'database' => env('DB_KESISWAAN_DATABASE', 'database_kesiswaan'),
|
||||||
|
'username' => env('DB_KESISWAAN_USERNAME', 'kesiswaan'),
|
||||||
|
'password' => env('DB_KESISWAAN_PASSWORD', ''),
|
||||||
|
'charset' => 'utf8mb4',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
'prefix' => '',
|
||||||
|
'strict' => false,
|
||||||
|
'engine' => null,
|
||||||
|
],
|
||||||
|
|
||||||
'mariadb' => [
|
'mariadb' => [
|
||||||
'driver' => 'mariadb',
|
'driver' => 'mariadb',
|
||||||
'url' => env('DB_URL'),
|
'url' => env('DB_URL'),
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ Route::middleware('auth:sanctum')->prefix('parent')->group(function () {
|
|||||||
Route::get('/students/{student}/points-history', [ParentStudentController::class, 'pointsHistory'])->name('api.parent.students.points-history');
|
Route::get('/students/{student}/points-history', [ParentStudentController::class, 'pointsHistory'])->name('api.parent.students.points-history');
|
||||||
Route::get('/students/{student}/violations-stats', [ParentStudentController::class, 'violationsStats'])->name('api.parent.students.violations-stats');
|
Route::get('/students/{student}/violations-stats', [ParentStudentController::class, 'violationsStats'])->name('api.parent.students.violations-stats');
|
||||||
Route::get('/students/{student}/grades', [ParentStudentController::class, 'grades'])->name('api.parent.students.grades');
|
Route::get('/students/{student}/grades', [ParentStudentController::class, 'grades'])->name('api.parent.students.grades');
|
||||||
|
Route::get('/students/{student}/classmates', [ParentStudentController::class, 'classmates'])->name('api.parent.students.classmates');
|
||||||
|
|
||||||
// Notifikasi & perangkat
|
// Notifikasi & perangkat
|
||||||
Route::get('/notifications', [ParentNotificationController::class, 'index'])->name('api.parent.notifications');
|
Route::get('/notifications', [ParentNotificationController::class, 'index'])->name('api.parent.notifications');
|
||||||
|
|||||||
Reference in New Issue
Block a user