55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php header('Content-Type: application/json');
|
|
require_once 'config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Get the latest snapshot
|
|
$stmt = $pdo->query("SELECT * FROM review_snapshot WHERE location_id = 'charlotte-heating' LIMIT 1");
|
|
$snapshot = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Get recent reviews
|
|
$stmt = $pdo->query("SELECT * FROM reviews WHERE location_id = 'charlotte-heating' ORDER BY review_date DESC LIMIT 10");
|
|
$recentReviews = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($snapshot) {
|
|
echo json_encode([
|
|
'success' => true,
|
|
'data' => [
|
|
'total_reviews' => (int)$snapshot['total_reviews'],
|
|
'avg_rating' => (float)$snapshot['avg_rating'],
|
|
'reviews_this_week' => (int)$snapshot['reviews_this_week'],
|
|
'reviews_this_month' => (int)$snapshot['reviews_this_month'],
|
|
'sources' => [
|
|
'google' => ['count' => (int)$snapshot['google_reviews'], 'avg' => (float)$snapshot['google_avg']],
|
|
'yelp' => ['count' => (int)$snapshot['yelp_reviews'], 'avg' => (float)$snapshot['yelp_avg']],
|
|
'facebook' => ['count' => (int)$snapshot['facebook_reviews'], 'avg' => (float)$snapshot['facebook_avg']]
|
|
],
|
|
'recent_reviews' => $recentReviews,
|
|
'last_synced' => $snapshot['last_synced']
|
|
]
|
|
]);
|
|
} else {
|
|
// Return default data if no snapshot exists yet
|
|
echo json_encode([
|
|
'success' => true,
|
|
'data' => [
|
|
'total_reviews' => 504,
|
|
'avg_rating' => 4.93,
|
|
'reviews_this_week' => 0,
|
|
'reviews_this_month' => 0,
|
|
'sources' => [
|
|
'google' => ['count' => 500, 'avg' => 4.95],
|
|
'yelp' => ['count' => 2, 'avg' => 3.0],
|
|
'facebook' => ['count' => 2, 'avg' => 3.0]
|
|
],
|
|
'recent_reviews' => [],
|
|
'last_synced' => null,
|
|
'message' => 'Using default data - N8N sync not yet configured'
|
|
]
|
|
]);
|
|
}
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|