Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DashboardController
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 index
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace App\Http\Controllers\WebAuth;
4
5use App\Http\Controllers\Controller;
6use App\Services\StatisticsService;
7use Illuminate\Http\Request;
8use Illuminate\Support\Facades\Log;
9use Illuminate\Support\Facades\Route; // <-- Add this import
10
11class DashboardController extends Controller
12{
13    protected $statisticsService;
14
15    public function __construct(StatisticsService $statisticsService)
16    {
17        $this->statisticsService = $statisticsService;
18    }
19
20    /**
21     * Show the application dashboard.
22     *
23     * @return \Illuminate\Contracts\Support\Renderable
24     */
25    public function index(Request $request)
26    {
27        $healthCheckUrl = config('app.url').'/romeo/api/v1/health/';
28        Log::info('url - '.$healthCheckUrl);
29
30        $healthStatus = [];
31
32        try {
33            $healthRequest = Request::create('/romeo/api/v1/health', 'GET');
34            $response = Route::dispatch($healthRequest);
35            $data = json_decode($response->getContent(), true);
36
37            if (isset($data['result']) && is_array($data['result'])) {
38                $healthStatus = $data['result'];
39            }
40            Log::info('test', [
41                'health' => $healthStatus,
42            ]);
43        } catch (\Exception $e) {
44            Log::info('error', [
45                'health' => $e->getMessage(),
46                'url' => $healthCheckUrl,
47            ]);
48            // Silently fail or log the error
49        }
50
51        $statistics = $this->statisticsService->getDashboardStatistics();
52
53        if ($request->query('json')) {
54            return response()->json([
55                'healthStatus' => $healthStatus,
56                'stats' => $statistics['stats'],
57                'usersByPlan' => $statistics['usersByPlan'],
58            ]);
59        }
60
61        return view('dashboard', [
62            'healthStatus' => $healthStatus,
63            'stats' => $statistics['stats'],
64            'usersByPlan' => $statistics['usersByPlan'],
65        ]);
66    }
67}