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