<?php
require_once __DIR__ . '/../../connect.php';

$passengerId = filterRequest("passenger_id");

$sql = "SELECT
    COALESCE(ROUND(AVG(ratingPassenger.rating), 2), 5) as rating
FROM
    ratingPassenger
WHERE
    ratingPassenger.passenger_id = :passenger_id";

$stmt = $con->prepare($sql);
$stmt->bindParam(':passenger_id', $passengerId);
$stmt->execute();

if ($stmt->rowCount() > 0) {
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    jsonSuccess($row);
} else {
    jsonError("No rating record found");
}
?>