diff --git a/api/song_requests.php b/api/song_requests.php index f0032ed..300a958 100644 --- a/api/song_requests.php +++ b/api/song_requests.php @@ -60,7 +60,28 @@ if ($method === 'POST') { } } - echo json_encode(['success' => true]); + // Check if this user is now the #1 listener of the week + $topStmt = $db->query(" + SELECT requester, COUNT(*) as total_requests + FROM song_requests + WHERE requester IS NOT NULL AND requester != '' AND requester != 'AnĂ³nimo' + AND created_at > DATE_SUB(NOW(), INTERVAL 7 DAY) + GROUP BY requester + ORDER BY total_requests DESC + LIMIT 1 + "); + $topListener = $topStmt->fetch(); + + $isNewTop = false; + if ($topListener && $topListener['requester'] === $requester) { + $isNewTop = true; + } + + echo json_encode([ + 'success' => true, + 'is_top' => $isNewTop, + 'top_name' => $topListener['requester'] ?? '' + ]); } catch (Exception $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); }