Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DashboardController
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
3.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 stats
83.33% covered (warning)
83.33%
10 / 12
0.00% covered (danger)
0.00%
0 / 1
2.02
1<?php
2
3namespace App\Http\Controllers\Api\V1;
4
5use App\Models\Article;
6use App\Models\Feed;
7use App\Models\PlatformAccount;
8use App\Models\PlatformChannel;
9use App\Services\DashboardStatsService;
10use Illuminate\Http\JsonResponse;
11use Illuminate\Http\Request;
12
13class DashboardController extends BaseController
14{
15    public function __construct(
16        private DashboardStatsService $dashboardStatsService
17    ) {}
18
19    /**
20     * Get dashboard statistics
21     */
22    public function stats(Request $request): JsonResponse
23    {
24        $period = $request->get('period', 'today');
25        
26        try {
27            // Get article stats from service
28            $articleStats = $this->dashboardStatsService->getStats($period);
29            
30            // Get system stats
31            $systemStats = $this->dashboardStatsService->getSystemStats();
32            
33            // Get available periods
34            $availablePeriods = $this->dashboardStatsService->getAvailablePeriods();
35            
36            return $this->sendResponse([
37                'article_stats' => $articleStats,
38                'system_stats' => $systemStats,
39                'available_periods' => $availablePeriods,
40                'current_period' => $period,
41            ]);
42        } catch (\Exception $e) {
43            return $this->sendError('Failed to fetch dashboard stats: ' . $e->getMessage(), [], 500);
44        }
45    }
46}