string('sort', 'created')->toString(); $dir = $request->string('dir', 'desc')->toString() === 'asc' ? 'asc' : 'desc'; $search = $request->string('q')->trim()->toString(); $connectionId = $request->integer('connection') ?: null; $allowedSort = ['db_name', 'created', 'active_days', 'state', 'last_index_activity', 'last_backup']; if (! in_array($sort, $allowedSort, true)) { $sort = 'created'; } $result = $this->connections->listerFor($connectionId)->listDatabases($sort, $dir, $search); if ($result['error'] ?? null) { return $this->fail($result['error'], 'service_error', 503); } return $this->ok($result['rows'], $result['meta']); } public function offline(Request $request, string $database): JsonResponse { $connectionId = $request->integer('connection') ?: null; try { $lister = $this->connections->listerFor($connectionId); $lister->makeOffline($database); return $this->ok(['database' => $database, 'state' => 'RESTRICTED']); } catch (InvalidArgumentException $e) { return $this->fail($e->getMessage(), 'validation_error', 422); } catch (Throwable) { return $this->fail('Failed to restrict database.', 'server_error', 500); } } }