/
itp_practice
/
itp_backend
Обзор
Документация
Войти
/
itp_practice
/
itp_backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/Http/Controllers/Admin/ProxyController.php
80 строк
2 KB
vivanenko
cart
27 май 2025, 11:45
27 май 2025, 11:45
934cbb5
Код
Авторство
О чём код?
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Services\Admin\ProxyService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; class ProxyController extends Controller { public function __construct( private readonly ProxyService $proxyService ) {} public function index(Request $request): JsonResponse { $perPage = $request->get('per_page', 15); $proxies = $this->proxyService->getPaginatedProxies($perPage); return response()->json([ 'data' => $proxies->items(), 'meta' => [ 'current_page' => $proxies->currentPage(), 'per_page' => $proxies->perPage(), 'total' => $proxies->total(), 'last_page' => $proxies->lastPage(), ], ]); } public function show(int $id): JsonResponse { $proxy = $this->proxyService->getProxy($id); if (!$proxy) { return response()->json(['message' => 'Proxy not found'], 404); } return response()->json(['data' => $proxy]); } public function store(Request $request): JsonResponse { // @todo добавить валидацию $proxy = $this->proxyService->createProxy($request->all()); return response()->json(['data' => $proxy], 201); } public function update(Request $request, int $id): JsonResponse { // @todo добавить валидацию $proxy = $this->proxyService->updateProxy($id, $request->all()); if (!$proxy) { return response()->json(['message' => 'Proxy not found'], 404); } return response()->json(['data' => $proxy]); } public function destroy(int $id): JsonResponse { if (!$this->proxyService->deleteProxy($id)) { return response()->json(['message' => 'Proxy not found'], 404); } return response()->json(null, 204); } public function upload(Request $request): JsonResponse { $request->validate([ 'proxies' => 'required|string', ]); $lines = preg_split('/\r?\n/', $request->input('proxies')); $created = $this->proxyService->batchCreateProxies($lines); return response()->json(['data' => $created], 201); } }