mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
98 lines
2.4 KiB
PHP
98 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Resources\AgentDenyResource;
|
|
use App\Models\AgentDeny;
|
|
use App\Repositories\AgentDenyRepository;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class TrackerController extends Controller
|
|
{
|
|
private $repository;
|
|
|
|
public function __construct(AgentDenyRepository $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
private function getRules(): array
|
|
{
|
|
return [
|
|
'family_id' => 'required|numeric',
|
|
'name' => 'required|string',
|
|
'peer_id' => 'required|string',
|
|
'agent' => 'required|string',
|
|
'comment' => 'required|string',
|
|
|
|
];
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$result = $this->repository->getList($request->all());
|
|
$resource = AgentDenyResource::collection($result);
|
|
return $this->success($resource);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate($this->getRules());
|
|
$result = $this->repository->store($request->all());
|
|
$resource = new AgentDenyResource($result);
|
|
return $this->success($resource);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$result = AgentDeny::query()->findOrFail($id);
|
|
$resource = new AgentDenyResource($result);
|
|
return $this->success($resource);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$request->validate($this->getRules());
|
|
$result = $this->repository->update($request->all(), $id);
|
|
$resource = new AgentDenyResource($result);
|
|
return $this->success($resource);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$result = $this->repository->delete($id);
|
|
return $this->success($result);
|
|
}
|
|
}
|