29 lines
814 B
PHP
29 lines
814 B
PHP
<?php
|
|
/**
|
|
* Trips List Endpoint (Example Module)
|
|
*/
|
|
|
|
use App\Core\Database;
|
|
use App\Middleware\AuthMiddleware;
|
|
use App\Middleware\RateLimitMiddleware;
|
|
|
|
// 1. Rate Limiting (e.g., 30 requests per minute)
|
|
RateLimitMiddleware::check(30, 60);
|
|
|
|
// 2. Auth Check
|
|
$decoded = AuthMiddleware::check();
|
|
|
|
// 3. Fetch Data
|
|
// Note: Assumes a 'trips' table exists based on the requested structure
|
|
$db = Database::getInstance();
|
|
try {
|
|
$stmt = $db->prepare("SELECT * FROM trips WHERE user_id = ? ORDER BY created_at DESC");
|
|
$stmt->execute([$decoded['user_id']]);
|
|
$trips = $stmt->fetchAll();
|
|
|
|
json_success($trips);
|
|
} catch (\PDOException $e) {
|
|
// If table doesn't exist, return empty for the sake of the skeleton
|
|
json_success([], 'Trips table not found, returning empty array for demonstration.');
|
|
}
|