big update all menus
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Nas;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Models\RadiusCluster;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class RadiusClusterController extends ApiController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorizeMaster($request);
|
||||
$data = $request->validate(['search'=>['nullable','string','max:255'],'status'=>['nullable',Rule::in(['planned','active','maintenance','inactive'])],'per_page'=>['nullable','integer','between:1,100']]);
|
||||
$rows = RadiusCluster::query()->when($data['search'] ?? null, fn ($q,$search) => $q->where(fn ($x) => $x->where('name','ILIKE',"%{$search}%")->orWhere('code','ILIKE',"%{$search}%")->orWhere('region','ILIKE',"%{$search}%")))->when($data['status'] ?? null, fn ($q,$status) => $q->where('status',$status))->orderBy('name')->paginate($data['per_page'] ?? 10);
|
||||
$rows->through(fn ($cluster) => $this->present($cluster));
|
||||
return $this->success($rows, 'Cluster RADIUS berhasil diambil');
|
||||
}
|
||||
|
||||
public function store(Request $request) { $this->authorizeMaster($request); return $this->created($this->present(RadiusCluster::create($this->validated($request))), 'Cluster RADIUS berhasil dibuat'); }
|
||||
public function show(Request $request, RadiusCluster $radiusCluster) { $this->authorizeMaster($request); return $this->success($this->present($radiusCluster), 'Detail cluster RADIUS berhasil diambil'); }
|
||||
public function update(Request $request, RadiusCluster $radiusCluster)
|
||||
{
|
||||
$this->authorizeMaster($request); $data=$this->validated($request,$radiusCluster);
|
||||
if (blank($data['provisioning_api_token'] ?? null)) unset($data['provisioning_api_token']);
|
||||
$radiusCluster->update($data); return $this->updated($this->present($radiusCluster->fresh()), 'Cluster RADIUS berhasil diperbarui');
|
||||
}
|
||||
public function destroy(Request $request, RadiusCluster $radiusCluster) { $this->authorizeMaster($request); $radiusCluster->delete(); return $this->deleted('Cluster RADIUS berhasil dihapus'); }
|
||||
|
||||
private function validated(Request $request, ?RadiusCluster $cluster=null): array
|
||||
{
|
||||
return $request->validate([
|
||||
'code'=>['required','alpha_dash','max:80',Rule::unique('radius_clusters','code')->ignore($cluster)], 'name'=>['required','string','max:255'], 'region'=>['nullable','string','max:80'],
|
||||
'auth_endpoints'=>['required','array','min:1','max:4'], 'auth_endpoints.*.host'=>['required','string','max:255'], 'auth_endpoints.*.port'=>['required','integer','between:1,65535'], 'auth_endpoints.*.priority'=>['required','integer','between:1,100'],
|
||||
'accounting_endpoints'=>['required','array','min:1','max:4'], 'accounting_endpoints.*.host'=>['required','string','max:255'], 'accounting_endpoints.*.port'=>['required','integer','between:1,65535'], 'accounting_endpoints.*.priority'=>['required','integer','between:1,100'],
|
||||
'coa_endpoints'=>['nullable','array','max:4'], 'coa_endpoints.*.host'=>['required','string','max:255'], 'coa_endpoints.*.port'=>['required','integer','between:1,65535'], 'coa_endpoints.*.priority'=>['required','integer','between:1,100'],
|
||||
'provisioning_api_url'=>['nullable','url:http,https','max:2000'], 'provisioning_api_token'=>['nullable','string','max:4000'], 'healthcheck_url'=>['nullable','url:http,https','max:2000'],
|
||||
'request_timeout'=>['required','integer','between:1,60'], 'retry_attempts'=>['required','integer','between:0,10'], 'status'=>['required',Rule::in(['planned','active','maintenance','inactive'])], 'notes'=>['nullable','string','max:5000'],
|
||||
]);
|
||||
}
|
||||
private function present(RadiusCluster $cluster): array { $data=$cluster->attributesToArray(); unset($data['provisioning_api_token']); return [...$data,'has_provisioning_api_token'=>filled($cluster->getRawOriginal('provisioning_api_token'))]; }
|
||||
private function authorizeMaster(Request $request): void { abort_unless($request->user()->isMasterAdmin(),403,'Infrastruktur RADIUS hanya dapat dikelola Master Admin.'); }
|
||||
}
|
||||
Reference in New Issue
Block a user