Preparing new api for hasil-belajar

This commit is contained in:
Gregorio Chiko Putra 2019-05-14 15:26:44 +07:00
parent 9b91fe40ce
commit dbe517c1fc
6 changed files with 65 additions and 4 deletions

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUrlFieldToAccessLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('access_logs', function (Blueprint $table) {
$table->string('url');
});
DB::table('access_logs')->update(['url' => '/api/siswa']);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('access_logs', function (Blueprint $table) {
$table->dropColumn('url');
});
}
}

View File

@ -22,6 +22,7 @@ var component = {
//Siswa.cariData({ //Siswa.cariData({
//nisn: e.target.elements.nisn.value, //nisn: e.target.elements.nisn.value,
//tanggalLahir: e.target.elements.tanggalLahir.value, //tanggalLahir: e.target.elements.tanggalLahir.value,
//src: 'sk-hasil-belajar',
//}); //});
} }
}, },

View File

@ -28,6 +28,7 @@ var component = {
Siswa.cariData({ Siswa.cariData({
nisn: e.target.elements.nisn.value, nisn: e.target.elements.nisn.value,
tanggalLahir: e.target.elements.tanggalLahir.value, tanggalLahir: e.target.elements.tanggalLahir.value,
src: 'surat-kelulusan',
}); });
} }
}, },

View File

@ -2,10 +2,11 @@ import m from "mithril"
var model = { var model = {
current: {}, current: {},
fetch: () => { fetch: src => {
m.request({ m.request({
method: 'get', method: 'get',
url: '/api/access_log', url: '/api/access_log',
data: { src },
}) })
.then(response => { .then(response => {
model.current = response; model.current = response;

24
resources/js/models/HasilBelajar.js vendored Normal file
View File

@ -0,0 +1,24 @@
import m from "mihtril"
import AccessLog from "./AccessLog"
var model = {
current: {},
error: {},
cariData: data => {
model.current = {};
m.request({
method: 'post',
url: '/api/hasil-belajar',
data,
})
.then(response => {
model.current = response;
console.log(model.current);
})
.catch(e => {
model.error = JSON.parse(e.message);
});
},
};
export default model;

View File

@ -45,14 +45,14 @@ Route::post('/siswa', function (Request $request) {
} }
// Write to log // Write to log
App\AccessLog::create(['siswa_id' => $siswa->id]); App\AccessLog::create(['siswa_id' => $siswa->id, 'src' => $request->src]);
return $siswa; return $siswa;
}); });
Route::get('/access_log', function () { Route::get('/access_log', function (Request $request) {
// Get the number of unique access // Get the number of unique access
$logs = DB::table('access_logs')->select(DB::raw('count(*) as num')) $logs = DB::table('access_logs')->select(DB::raw('count(*) as num where src = ?', $request->src))
->groupBy('siswa_id') ->groupBy('siswa_id')
->get() ->get()
->count(); ->count();