Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
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 / 13
0.00% covered (danger)
0.00%
0 / 2
12
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
 stats
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
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}