7920eb9f71
Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Reviewed-on: #12 Co-authored-by: ismailmasseran <ismail@koppkb.com> Co-committed-by: ismailmasseran <ismail@koppkb.com>
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Cawangan;
|
|
use App\Feature;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FeatureController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return response()->json([
|
|
'keys' => Feature::keys(),
|
|
'labels' => Feature::labels(),
|
|
]);
|
|
}
|
|
|
|
public function cawangan()
|
|
{
|
|
$cawangan = Cawangan::on('mysql7')
|
|
->orderBy('kodcaw')
|
|
->get(['kodcaw', 'details_caw']);
|
|
|
|
$maps = Feature::mapForMany($cawangan->pluck('kodcaw')->all());
|
|
|
|
$data = $cawangan->map(function ($c) use ($maps) {
|
|
return [
|
|
'kodcaw' => $c->kodcaw,
|
|
'details_caw' => $c->nama_cawangan,
|
|
'features' => $maps[$c->kodcaw] ?? Feature::defaults(),
|
|
];
|
|
});
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function update($kodcaw, $feature, Request $request)
|
|
{
|
|
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
|
|
if (!$cawangan) {
|
|
return response()->json(['message' => 'Cawangan tidak dijumpai'], 404);
|
|
}
|
|
|
|
if (!in_array($feature, Feature::keys(), true)) {
|
|
return response()->json(['message' => 'Ciri tidak sah'], 422);
|
|
}
|
|
|
|
$enabled = (int) $request->input('enabled') ? 1 : 0;
|
|
Feature::setEnabled($kodcaw, $feature, $enabled);
|
|
|
|
return response()->json([
|
|
'kodcaw' => $kodcaw,
|
|
'feature' => $feature,
|
|
'enabled' => $enabled,
|
|
'features' => Feature::mapFor($kodcaw),
|
|
]);
|
|
}
|
|
}
|