Explore/ismail (#12)
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>
This commit was merged in pull request #12.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user