diff --git a/api/app/Http/Controllers/StatisticsController.php b/api/app/Http/Controllers/StatisticsController.php index d0d529b..aabba2c 100644 --- a/api/app/Http/Controllers/StatisticsController.php +++ b/api/app/Http/Controllers/StatisticsController.php @@ -29,16 +29,23 @@ class StatisticsController extends Controller { $type = $request->query('type'); - $query = User::where('type', 'P') + $leaderboard = User::where('type', 'P') ->withCount(['wonGames' => function ($query) use ($type) { if ($type) { $query->where('type', $type); } }]) ->orderBy('won_games_count', 'desc') - ->take(10); + ->paginate(10); - $leaderboard = $query->get(['id', 'nickname', 'photo_avatar_filename']); + $leaderboard->through(function ($user) { + return [ + 'id' => $user->id, + 'nickname' => $user->nickname, + 'photo_avatar_filename' => $user->photo_avatar_filename, + 'won_games_count' => $user->won_games_count, + ]; + }); return response()->json($leaderboard); } diff --git a/api/sample-requests.http b/api/sample-requests.http index 2d3ba73..1172b90 100644 --- a/api/sample-requests.http +++ b/api/sample-requests.http @@ -53,4 +53,15 @@ Authorization: Bearer {{token}} "euros": 1, "payment_type": "MBWAY", "payment_reference": "912345678" -} \ No newline at end of file +} + +### Get public stats +GET http://localhost:8000/api/v1/leaderboard +Content-Type: application/json +Accept: application/json + +### Get me stats +GET http://localhost:8000/api/v1/statistics/me +Content-Type: application/json +Accept: application/json +Authorization: Bearer {{token}} \ No newline at end of file diff --git a/frontend/src/pages/home/HomePage.vue b/frontend/src/pages/home/HomePage.vue index 468ea96..1ab5a49 100644 --- a/frontend/src/pages/home/HomePage.vue +++ b/frontend/src/pages/home/HomePage.vue @@ -1,5 +1,6 @@ @@ -171,8 +242,8 @@ onMounted(async () => { -
Calculating your glory...
+Performance Overview
+Total Games
+{{ userStats.total_games }}
+Win Rate
+{{ userStats.win_rate }}
+Wins
+{{ userStats.total_wins }}
+Losses
+{{ userStats.total_losses }}
+{{ user.nickname }}
+Player
+{{ user.won_games_count }}
+Wins
+