fedi-feed-router/backend/app/Http/Controllers/Api/V1/DashboardController.php
2025-08-16 09:43:38 +02:00

46 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1;
use Domains\Article\Models\Article;
use Domains\Feed\Models\Feed;
use Domains\Platform\Models\PlatformAccount;
use Domains\Platform\Models\PlatformChannel;
use Domains\Article\Services\DashboardStatsService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DashboardController extends BaseController
{
public function __construct(
private DashboardStatsService $dashboardStatsService
) {}
/**
* Get dashboard statistics
*/
public function stats(Request $request): JsonResponse
{
$period = $request->get('period', 'today');
try {
// Get article stats from service
$articleStats = $this->dashboardStatsService->getStats($period);
// Get system stats
$systemStats = $this->dashboardStatsService->getSystemStats();
// Get available periods
$availablePeriods = $this->dashboardStatsService->getAvailablePeriods();
return $this->sendResponse([
'article_stats' => $articleStats,
'system_stats' => $systemStats,
'available_periods' => $availablePeriods,
'current_period' => $period,
]);
} catch (\Exception $e) {
return $this->sendError('Failed to fetch dashboard stats: ' . $e->getMessage(), [], 500);
}
}
}