Skip to content

Commit

Permalink
add shop rating calculating, fix #71
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu1997 committed Sep 3, 2019
1 parent 75510e7 commit b9faae2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public function spotInfo($spotId)
foreach ($spotComment as $key => $value) {
if(isset($value->rating))
$avgRate += $value->rating;
}
} //average rate calculate
return response()->json([
'item' => $spotInfo,
'comment' => $spotComment,
'Nearby' => $shopNearby,
'commentTotal' => $commentTotal,
'avgRate' => $avgRate / $commentTotal
'avgRate' => $avgRate/$commentTotal
]);
}
}
Expand Down Expand Up @@ -218,12 +218,16 @@ public function shopInfo($shopId)
// $shopLocation = $shopInfo->pluck('location')->first();
// $spotNearBy = Shop::where('location', $shopLocation)->first()->get();
$commentTotal = $shopComment->count();
$avgRate = 0;
foreach ($shopComment as $key => $value) {
if(isset($value->rating))
$avgRate += $value->rating;
} //average rate calculate
return response()->json([
'item' => $shopInfo,
'comment' => $shopComment,
// 'location' => $shopLocation,
// 'shopNearBy' => $spotNearBy
'commentTotal' => $commentTotal
'commentTotal' => $commentTotal,
'avgRate' => $avgRate/$commentTotal
]);
}
}
Expand Down

0 comments on commit b9faae2

Please sign in to comment.