Added endpoint to get authenticated user's transactions
This commit is contained in:
@@ -81,12 +81,15 @@ class StatisticsController extends Controller
|
||||
$totalGames = Game::count();
|
||||
$totalBlockedUsers = User::where('blocked', true)->count();
|
||||
|
||||
// 2. Games Breakdown by Type
|
||||
$gamesByType = Game::select('type', DB::raw('count(*) as total'))
|
||||
->groupBy('type')
|
||||
->get();
|
||||
|
||||
// 3. Games Per Month (CORRIGIDO PARA SQLITE)
|
||||
// SQLite usa strftime('%Y-%m', coluna) em vez de DATE_FORMAT
|
||||
$gamesPerMonth = Game::select(
|
||||
DB::raw('DATE_FORMAT(began_at, "%Y-%m") as month'),
|
||||
DB::raw("strftime('%Y-%m', began_at) as month"),
|
||||
DB::raw('count(*) as total')
|
||||
)
|
||||
->whereNotNull('began_at')
|
||||
@@ -95,16 +98,17 @@ class StatisticsController extends Controller
|
||||
->limit(12)
|
||||
->get();
|
||||
|
||||
|
||||
$totalCoinsPurchased = CoinTransaction::whereHas('type', function($q) {
|
||||
// 4. Financial/Coin Stats
|
||||
$totalCoinsPurchased = \App\Models\CoinTransaction::whereHas('type', function($q) {
|
||||
$q->where('name', 'Coin purchase');
|
||||
})
|
||||
->sum('coins');
|
||||
|
||||
$purchasesPerMonth = CoinTransaction::join('coin_transaction_types', 'coin_transactions.coin_transaction_type_id', '=', 'coin_transaction_types.id')
|
||||
// Calculate Purchases Per Month (CORRIGIDO PARA SQLITE)
|
||||
$purchasesPerMonth = \App\Models\CoinTransaction::join('coin_transaction_types', 'coin_transactions.coin_transaction_type_id', '=', 'coin_transaction_types.id')
|
||||
->where('coin_transaction_types.name', 'Coin purchase')
|
||||
->select(
|
||||
DB::raw('DATE_FORMAT(coin_transactions.transaction_datetime, "%Y-%m") as month'),
|
||||
DB::raw("strftime('%Y-%m', coin_transactions.transaction_datetime) as month"),
|
||||
DB::raw('SUM(coin_transactions.coins) as total_coins')
|
||||
)
|
||||
->groupBy('month')
|
||||
@@ -117,7 +121,7 @@ class StatisticsController extends Controller
|
||||
'total_players' => $totalPlayers,
|
||||
'total_games' => $totalGames,
|
||||
'blocked_users' => $totalBlockedUsers,
|
||||
'total_coins_purchased' => (int) $totalCoinsPurchased, // Cast to int
|
||||
'total_coins_purchased' => (int) $totalCoinsPurchased,
|
||||
],
|
||||
'charts' => [
|
||||
'games_by_type' => $gamesByType,
|
||||
|
||||
@@ -225,4 +225,9 @@ class UserController extends Controller
|
||||
|
||||
return response()->json($transactions);
|
||||
}
|
||||
|
||||
public function getMyTransactions(Request $request)
|
||||
{
|
||||
return $this->getTransactions($request, $request->user());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user