update
This commit is contained in:
@@ -3,16 +3,67 @@
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ReceivedCommentsInboxService;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
public function __construct(private readonly ReceivedCommentsInboxService $inbox) {}
|
||||
|
||||
public function received(Request $request): View
|
||||
{
|
||||
$user = $request->user();
|
||||
// Minimal placeholder: real implementation should query comments received or made
|
||||
$comments = [];
|
||||
$search = trim((string) $request->query('q', ''));
|
||||
$sort = strtolower((string) $request->query('sort', 'newest'));
|
||||
|
||||
return view('dashboard.comments', ['comments' => $comments]);
|
||||
if (! in_array($sort, ['newest', 'oldest'], true)) {
|
||||
$sort = 'newest';
|
||||
}
|
||||
|
||||
$baseQuery = $this->inbox->queryForUser($user)
|
||||
->with(['user.profile', 'artwork']);
|
||||
|
||||
if ($search !== '') {
|
||||
$baseQuery->where(function ($query) use ($search): void {
|
||||
$query->where('content', 'like', '%' . $search . '%')
|
||||
->orWhere('raw_content', 'like', '%' . $search . '%')
|
||||
->orWhereHas('artwork', function ($artworkQuery) use ($search): void {
|
||||
$artworkQuery->where('title', 'like', '%' . $search . '%')
|
||||
->orWhere('slug', 'like', '%' . $search . '%');
|
||||
})
|
||||
->orWhereHas('user', function ($userQuery) use ($search): void {
|
||||
$userQuery->where('username', 'like', '%' . $search . '%')
|
||||
->orWhere('name', 'like', '%' . $search . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$orderedQuery = (clone $baseQuery)
|
||||
->orderBy('created_at', $sort === 'oldest' ? 'asc' : 'desc');
|
||||
|
||||
$comments = $orderedQuery->paginate(12)->withQueryString();
|
||||
|
||||
$statsBaseQuery = clone $baseQuery;
|
||||
$freshlyClearedCount = $this->inbox->unreadCountForUser($user);
|
||||
$totalComments = (clone $statsBaseQuery)->count();
|
||||
$recentComments = (clone $statsBaseQuery)->where('created_at', '>=', now()->subDays(7))->count();
|
||||
$uniqueCommenters = (clone $statsBaseQuery)->distinct('user_id')->count('user_id');
|
||||
$activeArtworks = (clone $statsBaseQuery)->distinct('artwork_id')->count('artwork_id');
|
||||
|
||||
$this->inbox->markInboxRead($user);
|
||||
|
||||
return view('dashboard.comments', [
|
||||
'comments' => $comments,
|
||||
'search' => $search,
|
||||
'sort' => $sort,
|
||||
'freshlyClearedCount' => $freshlyClearedCount,
|
||||
'stats' => [
|
||||
'total' => $totalComments,
|
||||
'recent' => $recentComments,
|
||||
'commenters' => $uniqueCommenters,
|
||||
'artworks' => $activeArtworks,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DashboardPreference;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DashboardPreferenceController extends Controller
|
||||
{
|
||||
public function updateShortcuts(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'pinned_spaces' => ['present', 'array', 'max:' . DashboardPreference::MAX_PINNED_SPACES],
|
||||
'pinned_spaces.*' => ['string'],
|
||||
]);
|
||||
|
||||
$pinnedSpaces = DashboardPreference::sanitizePinnedSpaces($validated['pinned_spaces'] ?? []);
|
||||
|
||||
DashboardPreference::query()->updateOrCreate(
|
||||
['user_id' => $request->user()->id],
|
||||
['pinned_spaces' => $pinnedSpaces]
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'pinned_spaces' => $pinnedSpaces,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
25
app/Http/Controllers/Dashboard/NotificationController.php
Normal file
25
app/Http/Controllers/Dashboard/NotificationController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\NotificationService;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NotificationController extends Controller
|
||||
{
|
||||
public function __construct(private readonly NotificationService $notifications) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
$payload = $this->notifications->listForUser($request->user(), $page, 15);
|
||||
|
||||
return view('dashboard.notifications', [
|
||||
'notifications' => collect($payload['data'] ?? []),
|
||||
'notificationsMeta' => $payload['meta'] ?? [],
|
||||
'unreadCount' => (int) ($payload['unread_count'] ?? 0),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user