diff --git a/public/index.php b/public/index.php index 87108e6..fa03ccf 100644 --- a/public/index.php +++ b/public/index.php @@ -59,6 +59,12 @@ $app->get('/', function (Request $request, Response $response) { return $response->withHeader('Content-Type', 'text/html'); }); +// Маршрут для страницы лент +$app->get('/feeds', function (Request $request, Response $response) { + $response->getBody()->write(file_get_contents(__DIR__ . '/../templates/feeds.html')); + return $response->withHeader('Content-Type', 'text/html'); +}); + // Обработка ошибок $errorMiddleware = $app->addErrorMiddleware($_ENV['APP_DEBUG'] ?? false, true, true); diff --git a/src/Controllers/ApiController.php b/src/Controllers/ApiController.php index 3b69530..eb66442 100644 --- a/src/Controllers/ApiController.php +++ b/src/Controllers/ApiController.php @@ -23,12 +23,23 @@ class ApiController try { $params = $request->getQueryParams(); + // Параметры пагинации + $page = isset($params['page']) ? max(1, (int)$params['page']) : 1; + $limit = isset($params['limit']) ? min(100, max(1, (int)$params['limit'])) : 20; // максимум 100 на страницу + $offset = ($page - 1) * $limit; + $sql = "SELECT f.*, c.name as category_name, o.name as owner_name FROM feeds f LEFT JOIN categories c ON f.category_id = c.id LEFT JOIN owners o ON f.owner_id = o.id WHERE f.status = 'active'"; + $countSql = "SELECT COUNT(*) + FROM feeds f + LEFT JOIN categories c ON f.category_id = c.id + LEFT JOIN owners o ON f.owner_id = o.id + WHERE f.status = 'active'"; + $conditions = []; $bindings = []; @@ -48,10 +59,21 @@ class ApiController } if (!empty($conditions)) { - $sql .= " AND " . implode(" AND ", $conditions); + $whereClause = " AND " . implode(" AND ", $conditions); + $sql .= $whereClause; + $countSql .= $whereClause; } - $sql .= " ORDER BY f.created_at DESC"; + $sql .= " ORDER BY f.created_at DESC LIMIT :limit OFFSET :offset"; + + // Подсчет общего количества + $countStmt = $this->db->prepare($countSql); + $countStmt->execute($bindings); + $total = $countStmt->fetchColumn(); + + // Выборка данных + $bindings[':limit'] = $limit; + $bindings[':offset'] = $offset; $stmt = $this->db->prepare($sql); $stmt->execute($bindings); @@ -69,7 +91,18 @@ class ApiController $feed['tags'] = array_column($tagStmt->fetchAll(), 'name'); } - $response->getBody()->write(json_encode($feeds)); + // Подготовка ответа с пагинацией + $responseData = [ + 'data' => $feeds, + 'pagination' => [ + 'current_page' => $page, + 'per_page' => $limit, + 'total' => $total, + 'total_pages' => ceil($total / $limit) + ] + ]; + + $response->getBody()->write(json_encode($responseData)); return $response->withHeader('Content-Type', 'application/json'); } catch (\Exception $e) { $response->getBody()->write(json_encode(['error' => $e->getMessage()])); diff --git a/templates/feeds.html b/templates/feeds.html new file mode 100644 index 0000000..22ce840 --- /dev/null +++ b/templates/feeds.html @@ -0,0 +1,451 @@ + + + + + + Список RSS лент - RSS Hub for Agents + + + +
+
+

Список RSS лент

+

Просмотр зарегистрированных RSS/Atom лент с фильтрацией и пагинацией

+
+ +
+ + +
+ + + +
+
+ +
+ + + + + + + + + + + + + + + + + +
IDНазваниеURLКатегорияТегиВладелецДата добавления
Загрузка данных...
+
+ + + + +
+ + + + \ No newline at end of file