<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::post('/siswa', 'SiswaController')->name('siswa.retrieve');

Route::post('/hasil_belajar', 'HasilBelajarController')->name('hasilBelajar.retrieve');

Route::get('/access_log', 'AccessLogController')->name('accessLog.fetch');
Route::post('/access_log', function(Request $request) {
    try {
        App\AccessLog::create(['siswa_id' => $request->siswaId, 'src' => $request->src]);
    } catch (Exception $e) {
        return response()->json([
            'message' => $e->getMessage(),
            'errors' => [
                'create' => ['Telah terjadi kesalahan pada server.'],
            ],
        ], (int)$e->getCode() ?: 500);
    }
})->name('accessLog.create');
