This commit is contained in:
2026-03-20 21:17:26 +01:00
parent 1a62fcb81d
commit 29c3ff8572
229 changed files with 13147 additions and 2577 deletions

View File

@@ -5,25 +5,60 @@ declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Artwork;
use App\Models\DashboardPreference;
use App\Models\Story;
use App\Models\User;
use App\Services\ReceivedCommentsInboxService;
use App\Services\XPService;
use App\Support\AvatarUrl;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
final class DashboardController extends Controller
{
public function __construct(
private readonly XPService $xp,
private readonly ReceivedCommentsInboxService $receivedCommentsInbox,
) {}
public function index(Request $request)
{
$user = $request->user();
$xpSummary = $this->xp->summary((int) $user->id);
$artworksCount = Artwork::query()
->where('user_id', $user->id)
->whereNull('deleted_at')
->count();
$storiesCount = Story::query()->where('creator_id', $user->id)->count();
$followersCount = (int) DB::table('user_followers')->where('user_id', $user->id)->count();
$followingCount = (int) DB::table('user_followers')->where('follower_id', $user->id)->count();
$favoritesCount = (int) DB::table('artwork_favourites')->where('user_id', $user->id)->count();
$unreadNotificationsCount = $user->unreadNotifications()->count();
$receivedCommentsCount = $this->receivedCommentsInbox->unreadCountForUser($user);
$isCreator = $artworksCount > 0;
$pinnedSpaces = DashboardPreference::pinnedSpacesForUser($user);
return view('dashboard', [
'page_title' => 'Dashboard',
'dashboard_user_name' => $user?->username ?: $user?->name ?: 'Creator',
'dashboard_is_creator' => Artwork::query()->where('user_id', $user->id)->exists(),
'dashboard_is_creator' => $isCreator,
'dashboard_level' => $xpSummary['level'],
'dashboard_rank' => $xpSummary['rank'],
'dashboard_received_comments_count' => $receivedCommentsCount,
'dashboard_overview' => [
'artworks' => $artworksCount,
'stories' => $storiesCount,
'followers' => $followersCount,
'following' => $followingCount,
'favorites' => $favoritesCount,
'notifications' => $unreadNotificationsCount,
'received_comments' => $receivedCommentsCount,
],
'dashboard_preferences' => [
'pinned_spaces' => $pinnedSpaces,
],
]);
}
@@ -195,6 +230,8 @@ final class DashboardController extends Controller
'username' => $artwork->user?->username,
'name' => $artwork->user?->name,
'url' => $artwork->user?->username ? '/@' . $artwork->user->username : null,
'level' => (int) ($artwork->user?->level ?? 1),
'rank' => (string) ($artwork->user?->rank ?? 'Newbie'),
],
];
})
@@ -238,6 +275,8 @@ final class DashboardController extends Controller
'users.id',
'users.username',
'users.name',
'users.level',
'users.rank',
'up.avatar_hash',
DB::raw('COALESCE(us.followers_count, 0) as followers_count'),
DB::raw('COALESCE(us.uploads_count, 0) as uploads_count'),
@@ -255,6 +294,8 @@ final class DashboardController extends Controller
'name' => $row->name,
'url' => $username !== '' ? '/@' . $username : null,
'avatar' => AvatarUrl::forUser((int) $row->id, $row->avatar_hash, 64),
'level' => (int) ($row->level ?? 1),
'rank' => (string) ($row->rank ?? 'Newbie'),
'followers_count' => (int) $row->followers_count,
'uploads_count' => (int) $row->uploads_count,
];