Allplmmpliedl manual JWT check and restored all driver fields68j2
This commit is contained in:
@@ -112,23 +112,37 @@ class RatingController extends Controller
|
||||
if (!$id) {
|
||||
return response()->json(['status' => 'failure', 'message' => 'Driver ID required'], 400);
|
||||
}
|
||||
$ratings = DB::connection('primary')->table('ratingDriver')
|
||||
->where('driver_id', $id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(50)
|
||||
->get();
|
||||
|
||||
$avg = DB::connection('primary')->table('ratingDriver')
|
||||
->where('driver_id', $id)->avg('rating');
|
||||
$summaryOnly = $request->input('summary_only', true);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => [
|
||||
// Cache rating summary for 1 hour
|
||||
$cacheKey = "driver_rating_summary:{$id}";
|
||||
$summary = \Illuminate\Support\Facades\Cache::remember($cacheKey, 3600, function () use ($id) {
|
||||
$avg = DB::connection('primary')->table('ratingDriver')
|
||||
->where('driver_id', $id)->avg('rating');
|
||||
$count = DB::connection('primary')->table('ratingDriver')
|
||||
->where('driver_id', $id)->count();
|
||||
|
||||
return [
|
||||
'average' => round($avg ?? 5.0, 2),
|
||||
'count' => $ratings->count(),
|
||||
'ratings' => $ratings,
|
||||
],
|
||||
]);
|
||||
'count' => $count,
|
||||
];
|
||||
});
|
||||
|
||||
$response = [
|
||||
'status' => 'success',
|
||||
'message' => $summary,
|
||||
];
|
||||
|
||||
if (!$summaryOnly) {
|
||||
$response['message']['ratings'] = DB::connection('primary')->table('ratingDriver')
|
||||
->where('driver_id', $id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(50)
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/** GET /v2/ratings/passenger/{id} */
|
||||
|
||||
Reference in New Issue
Block a user