From 16f8d3bdfcd50c34f71124e117d475a5619aa09e Mon Sep 17 00:00:00 2001 From: Edd Date: Wed, 31 Dec 2025 23:57:54 +0000 Subject: [PATCH] Created statistics personal and general --- .../Http/Controllers/StatisticsController.php | 13 +- api/sample-requests.http | 13 +- frontend/src/pages/home/HomePage.vue | 225 ++++++++++++++++-- frontend/src/stores/api.js | 14 ++ 4 files changed, 240 insertions(+), 25 deletions(-) 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 () => { -
- Loading +
+ Loading more...
@@ -238,5 +309,117 @@ onMounted(async () => { + +
+ + +
+ + My Statistics + + +
+
+ + +
+
+
+

Calculating your glory...

+
+ +
+
+

{{ userStats.nickname }}

+

Performance Overview

+
+ +
+
+

Total Games

+

{{ userStats.total_games }}

+
+
+

Win Rate

+

{{ userStats.win_rate }}

+
+
+

Wins

+

{{ userStats.total_wins }}

+
+
+

Losses

+

{{ userStats.total_losses }}

+
+
+ +
+
+ Win/Loss Ratio + {{ userStats.total_wins }}W - {{ userStats.total_losses }}L +
+
+
+
+
+
+
+
+
+ +
+ + +
+ + Leaderboard + + +
+
+ + +
+ +
+ + #{{ index + 1 }} + + Avatar +
+

{{ user.nickname }}

+

Player

+
+
+ +
+

{{ user.won_games_count }}

+

Wins

+
+
+ +
+ Loading rankings... +
+
+
+
+ + +
+ +
diff --git a/frontend/src/stores/api.js b/frontend/src/stores/api.js index 4cdba6e..2fec007 100644 --- a/frontend/src/stores/api.js +++ b/frontend/src/stores/api.js @@ -102,6 +102,18 @@ export const useAPIStore = defineStore('api', () => { return axios.get(`${API_BASE_URL}/users/${authStore.currentUserID}/transactions?${queryParams}`) } + const getLeaderboard = (params = {}) => { + const queryParams = new URLSearchParams({ + page: params.page || 1, + }).toString() + + return axios.get(`${API_BASE_URL}/leaderboard?${queryParams}`) + } + + const getCurrentUserStats = () => { + return axios.get(`${API_BASE_URL}/statistics/me`) + } + return { postLogin, postLogout, @@ -109,6 +121,8 @@ export const useAPIStore = defineStore('api', () => { getGames, getCurrentUserMatches, getCurrentUserTransactions, + getCurrentUserStats, + getLeaderboard, gameQueryParameters, } })