Front/back split - first draft
This commit is contained in:
parent
01493ac0bf
commit
714be5e7f3
10203 changed files with 1064757 additions and 219 deletions
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePublication;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardStatsService
|
||||
{
|
||||
/**
|
||||
* @return array{articles_fetched: int, articles_published: int, published_percentage: float}
|
||||
*/
|
||||
public function getStats(string $period = 'today'): array
|
||||
{
|
||||
$dateRange = $this->getDateRange($period);
|
||||
|
||||
$articlesFetched = Article::when($dateRange, function ($query) use ($dateRange) {
|
||||
return $query->whereBetween('created_at', $dateRange);
|
||||
})->count();
|
||||
|
||||
$articlesPublished = ArticlePublication::when($dateRange, function ($query) use ($dateRange) {
|
||||
return $query->whereBetween('published_at', $dateRange);
|
||||
})->count();
|
||||
|
||||
$publishedPercentage = $articlesFetched > 0
|
||||
? round(($articlesPublished / $articlesFetched) * 100, 1)
|
||||
: 0.0;
|
||||
|
||||
return [
|
||||
'articles_fetched' => $articlesFetched,
|
||||
'articles_published' => $articlesPublished,
|
||||
'published_percentage' => $publishedPercentage,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getAvailablePeriods(): array
|
||||
{
|
||||
return [
|
||||
'today' => 'Today',
|
||||
'week' => 'This Week',
|
||||
'month' => 'This Month',
|
||||
'year' => 'This Year',
|
||||
'all' => 'All Time',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: Carbon, 1: Carbon}|null
|
||||
*/
|
||||
private function getDateRange(string $period): ?array
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
return match ($period) {
|
||||
'today' => [$now->copy()->startOfDay(), $now->copy()->endOfDay()],
|
||||
'week' => [$now->copy()->startOfWeek(), $now->copy()->endOfWeek()],
|
||||
'month' => [$now->copy()->startOfMonth(), $now->copy()->endOfMonth()],
|
||||
'year' => [$now->copy()->startOfYear(), $now->copy()->endOfYear()],
|
||||
'all' => null, // No date filtering for all-time stats
|
||||
default => [$now->copy()->startOfDay(), $now->copy()->endOfDay()],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional stats for dashboard
|
||||
* @return array{total_feeds: int, active_feeds: int, total_channels: int, active_channels: int, total_routes: int, active_routes: int}
|
||||
*/
|
||||
public function getSystemStats(): array
|
||||
{
|
||||
return [
|
||||
'total_feeds' => \App\Models\Feed::count(),
|
||||
'active_feeds' => \App\Models\Feed::where('is_active', true)->count(),
|
||||
'total_channels' => \App\Models\PlatformChannel::count(),
|
||||
'active_channels' => \App\Models\PlatformChannel::where('is_active', true)->count(),
|
||||
'total_routes' => \App\Models\Route::count(),
|
||||
'active_routes' => \App\Models\Route::where('is_active', true)->count(),
|
||||
];
|
||||
}
|
||||
}
|
||||
98
backend/app/Services/DashboardStatsService.php
Normal file
98
backend/app/Services/DashboardStatsService.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePublication;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardStatsService
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStats(string $period = 'today'): array
|
||||
{
|
||||
$todayRange = $this->getDateRange('today');
|
||||
$weekRange = $this->getDateRange('week');
|
||||
$monthRange = $this->getDateRange('month');
|
||||
|
||||
// Get totals for different periods
|
||||
$totalToday = Article::whereBetween('created_at', $todayRange)->count();
|
||||
$totalWeek = Article::whereBetween('created_at', $weekRange)->count();
|
||||
$totalMonth = Article::whereBetween('created_at', $monthRange)->count();
|
||||
|
||||
// Get approved articles (using approval_status field)
|
||||
$approvedToday = Article::whereBetween('created_at', $todayRange)
|
||||
->where('approval_status', 'approved')->count();
|
||||
$approvedWeek = Article::whereBetween('created_at', $weekRange)
|
||||
->where('approval_status', 'approved')->count();
|
||||
$approvedMonth = Article::whereBetween('created_at', $monthRange)
|
||||
->where('approval_status', 'approved')->count();
|
||||
|
||||
// Calculate approval percentages
|
||||
$approvalPercentageToday = $totalToday > 0 ? round(($approvedToday / $totalToday) * 100, 1) : 0.0;
|
||||
$approvalPercentageWeek = $totalWeek > 0 ? round(($approvedWeek / $totalWeek) * 100, 1) : 0.0;
|
||||
$approvalPercentageMonth = $totalMonth > 0 ? round(($approvedMonth / $totalMonth) * 100, 1) : 0.0;
|
||||
|
||||
return [
|
||||
'total_today' => $totalToday,
|
||||
'total_week' => $totalWeek,
|
||||
'total_month' => $totalMonth,
|
||||
'approved_today' => $approvedToday,
|
||||
'approved_week' => $approvedWeek,
|
||||
'approved_month' => $approvedMonth,
|
||||
'approval_percentage_today' => $approvalPercentageToday,
|
||||
'approval_percentage_week' => $approvalPercentageWeek,
|
||||
'approval_percentage_month' => $approvalPercentageMonth,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getAvailablePeriods(): array
|
||||
{
|
||||
return [
|
||||
'today' => 'Today',
|
||||
'week' => 'This Week',
|
||||
'month' => 'This Month',
|
||||
'year' => 'This Year',
|
||||
'all' => 'All Time',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: Carbon, 1: Carbon}|null
|
||||
*/
|
||||
private function getDateRange(string $period): ?array
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
return match ($period) {
|
||||
'today' => [$now->copy()->startOfDay(), $now->copy()->endOfDay()],
|
||||
'week' => [$now->copy()->startOfWeek(), $now->copy()->endOfWeek()],
|
||||
'month' => [$now->copy()->startOfMonth(), $now->copy()->endOfMonth()],
|
||||
'year' => [$now->copy()->startOfYear(), $now->copy()->endOfYear()],
|
||||
'all' => null, // No date filtering for all-time stats
|
||||
default => [$now->copy()->startOfDay(), $now->copy()->endOfDay()],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional stats for dashboard
|
||||
*/
|
||||
public function getSystemStats(): array
|
||||
{
|
||||
return [
|
||||
'total_feeds' => \App\Models\Feed::count(),
|
||||
'active_feeds' => \App\Models\Feed::where('is_active', true)->count(),
|
||||
'total_platform_accounts' => \App\Models\PlatformAccount::count(),
|
||||
'active_platform_accounts' => \App\Models\PlatformAccount::where('is_active', true)->count(),
|
||||
'total_platform_channels' => \App\Models\PlatformChannel::count(),
|
||||
'active_platform_channels' => \App\Models\PlatformChannel::where('is_active', true)->count(),
|
||||
'total_routes' => \App\Models\Route::count(),
|
||||
'active_routes' => \App\Models\Route::where('is_active', true)->count(),
|
||||
];
|
||||
}
|
||||
}
|
||||
8773
backend/composer.lock
generated
Normal file
8773
backend/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue