Skip to content

Commit

Permalink
return average rate, fix #71
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu1997 committed Sep 3, 2019
1 parent de8f07c commit 75510e7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,19 @@ public function spotInfo($spotId)
BETWEEN '.$long.' - '.$radius.'/(69 * COS(RADIANS('.$lat.')))
AND '.$long.' + '.$radius.'/(69 * COS(RADIANS('.$lat.'))))r
WHERE `distance` < '. $radius .'
ORDER BY `distance` ASC');
return response()->json([
'item' => $spotInfo,
'comment' => $spotComment,
'lat' => $lat,
'long' => $long,
// 'location' => $spotLocation,
'Nearby' => $shopNearby,
'commentTotal' => $commentTotal
]);
ORDER BY `distance` ASC'); //radius search raw expression
$avgRate = 0;
foreach ($spotComment as $key => $value) {
if(isset($value->rating))
$avgRate += $value->rating;
}
return response()->json([
'item' => $spotInfo,
'comment' => $spotComment,
'Nearby' => $shopNearby,
'commentTotal' => $commentTotal,
'avgRate' => $avgRate / $commentTotal
]);
}
}

Expand Down

0 comments on commit 75510e7

Please sign in to comment.