Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.62% |
11 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DashboardController | |
84.62% |
11 / 13 |
|
50.00% |
1 / 2 |
3.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| stats | |
83.33% |
10 / 12 |
|
0.00% |
0 / 1 |
2.02 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Api\V1; |
| 4 | |
| 5 | use App\Models\Article; |
| 6 | use App\Models\Feed; |
| 7 | use App\Models\PlatformAccount; |
| 8 | use App\Models\PlatformChannel; |
| 9 | use App\Services\DashboardStatsService; |
| 10 | use Illuminate\Http\JsonResponse; |
| 11 | use Illuminate\Http\Request; |
| 12 | |
| 13 | class 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 | } |