<?php
require_once __DIR__ . '/../../connect.php';
$driver_id = filterRequest("driver_id");

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

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

if ($stmt->rowCount() > 0) {
    // Fetch the record
    $row = $stmt->fetchAll(PDO::FETCH_ASSOC);
   
    jsonSuccess($row);
} else {
    // Print a failure message
    jsonError($message = "No rating record found");
}
?>
