Skip to content

Commit e80e6a2

Browse files
authored
fix: remove remaining subject/chapter slug selects and display resource comments count on feed (#465)
1 parent 8e8170b commit e80e6a2

6 files changed

Lines changed: 43 additions & 22 deletions

File tree

‎app/Http/Controllers/ForumController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function index(Request $request): Response
4747
->when(! ($myPosts && auth()->check()), fn ($q) => $q->approved())
4848
->with([
4949
'user:id,name,username,image_path,institution,is_verified',
50-
'subject:id,name,course,slug',
51-
'node:id,name,slug',
50+
'subject:id,name,course',
51+
'chapter:id,name',
5252
])
5353
->filter($filters);
5454

‎app/Http/Controllers/HomeController.php‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public function index(Request $request)
3838
}
3939

4040
return $subjectsQuery->orderBy('sort_order', 'asc')
41-
->with(['nodes' => function ($q) {
42-
$q->select('id', 'subject_id', 'name', 'slug')
41+
->with(['chapters' => function ($q) {
42+
$q->select('id', 'subject_id', 'name')
4343
->orderBy('sort_order');
4444
}])
45-
->get(['id', 'name', 'slug', 'course', 'group'])
45+
->get(['id', 'name', 'course', 'group'])
4646
->toArray();
4747
});
4848

@@ -102,19 +102,27 @@ private function getFeed(string $course, string $group, string $sort, int $page
102102
});
103103
})
104104
->when($currentUserId, fn ($q) => $q->where('user_id', '!=', $currentUserId))
105-
->with(['user:id,name,username,image_path,institution,is_verified', 'subject:id,name,slug,group', 'node:id,name,slug'])
105+
->with(['user:id,name,username,image_path,institution,is_verified', 'subject:id,name,group', 'chapter:id,name'])
106106
->withCount('answers');
107107

108108
// 2. Resources (4 items)
109109
$resourcesQuery = Resource::approved()
110-
->whereHas('node.subject', function ($s) use ($course, $group) {
111-
$s->where('course', $course);
112-
if ($group) {
113-
$s->whereIn('group', [$group, 'common']);
114-
}
110+
->where(function ($query) use ($course, $group) {
111+
$query->whereHas('subject', function ($s) use ($course, $group) {
112+
$s->where('course', $course);
113+
if ($group) {
114+
$s->whereIn('group', [$group, 'common']);
115+
}
116+
})->orWhereHas('chapter.subject', function ($s) use ($course, $group) {
117+
$s->where('course', $course);
118+
if ($group) {
119+
$s->whereIn('group', [$group, 'common']);
120+
}
121+
});
115122
})
116123
->when($currentUserId, fn ($q) => $q->where('user_id', '!=', $currentUserId))
117-
->with(['user:id,name,username,image_path,institution,is_verified', 'node:id,name,slug,subject_id', 'node.subject:id,name,course,slug,group']);
124+
->with(['user:id,name,username,image_path,institution,is_verified', 'chapter:id,name,subject_id', 'chapter.subject:id,name,course,group', 'subject:id,name,course,group'])
125+
->withCount('comments');
118126

119127
// 3. Blogs (2 items)
120128
$blogsQuery = Blog::where('is_published', true)

‎app/Http/Controllers/NoteController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function index(Request $request): Response
7474
$query->where('chapter_id', (int) $chapterId);
7575
}
7676

77-
if (in_array($type, ['note', 'video', 'practical', 'other'], true)) {
77+
if (in_array($type, ['note', 'lecture_sheet', 'marked_book', 'video', 'practical', 'other'], true)) {
7878
$query->where('resource_type', $type);
7979
}
8080

‎app/Http/Controllers/ResourceController.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public function show($id)
7373
// Fallback for non-approved (pending / rejected) viewing by owner or moderator
7474
$resource = Resource::with([
7575
'user:id,name,username,image_path',
76-
'node:id,name,slug,subject_id',
77-
'node.subject:id,name,slug,course',
78-
'subject:id,name,slug,course',
76+
'chapter:id,name,subject_id',
77+
'chapter.subject:id,name,course',
78+
'subject:id,name,course',
7979
])->findOrFail($id);
8080

8181
if (! $resource->relationLoaded('subject') || ! $resource->subject) {
82-
$resource->setRelation('subject', $resource->node?->subject);
82+
$resource->setRelation('subject', $resource->chapter?->subject);
8383
}
8484

8585
$isOwner = $user && $user->id === $resource->user_id;
@@ -99,8 +99,8 @@ public function show($id)
9999
$subjects = ($isModerator || $isOwner)
100100
? Subject::where('is_disabled', false)
101101
->orderBy('sort_order')
102-
->with(['nodes' => fn ($q) => $q->select('id', 'subject_id', 'name', 'slug')->orderBy('sort_order')])
103-
->get(['id', 'name', 'slug', 'course', 'group'])
102+
->with(['chapters' => fn ($q) => $q->select('id', 'subject_id', 'name')->orderBy('sort_order')])
103+
->get(['id', 'name', 'course', 'group'])
104104
: [];
105105

106106
$comments = ResourceComment::where('resource_id', $id)

‎app/Http/Controllers/UserProfileController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function show(string $username)
149149

150150
$forumPosts = ForumPost::where('user_id', $user->id)
151151
->approved()
152-
->with(['subject:id,name,course,slug', 'node:id,name,slug'])
152+
->with(['subject:id,name,course', 'chapter:id,name'])
153153
->latest()
154154
->take(5)
155155
->get();
@@ -169,7 +169,7 @@ public function show(string $username)
169169

170170
$notes = Resource::where('user_id', $user->id)
171171
->when(! $isOwner, fn ($q) => $q->where('status', 'approved'))
172-
->with(['node:id,name,slug,subject_id', 'node.subject:id,name,course,slug', 'subject:id,name,course,slug'])
172+
->with(['chapter:id,name,subject_id', 'chapter.subject:id,name,course', 'subject:id,name,course'])
173173
->latest('id')
174174
->take(5)
175175
->get();

‎resources/js/components/resources/ResourceFeedCard.vue‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
FileText,
77
FlaskConical,
88
Loader2,
9+
MessageSquare,
910
Play,
1011
Share2,
1112
Video,
@@ -61,6 +62,7 @@ interface Resource {
6162
vote_score: number;
6263
upvotes_count?: number;
6364
downvotes_count?: number;
65+
comments_count?: number;
6466
created_at: string;
6567
user?: User;
6668
node?: NodeItem | null;
@@ -443,7 +445,7 @@ const shareResource = async () => {
443445
<template v-if="resource.node?.subject">
444446
<span class="text-slate-300 dark:text-gray-600">•</span>
445447
<Link
446-
:href="`/${resource.node.subject.slug}`"
448+
:href="`/notes?subject=${resource.node.subject.id}`"
447449
@click.stop
448450
class="shrink-0 transition hover:text-indigo-600 dark:hover:text-indigo-400"
449451
>
@@ -545,6 +547,17 @@ const shareResource = async () => {
545547
direction="horizontal"
546548
size="sm"
547549
/>
550+
551+
<!-- Comment Count Button (Exactly matching Forum & Blog) -->
552+
<Link
553+
:href="`/resources/${resource.id}#comments`"
554+
class="inline-flex items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-2.5 py-1 text-xs font-semibold text-slate-700 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800"
555+
>
556+
<MessageSquare
557+
class="h-3.5 w-3.5 text-purple-600 dark:text-purple-400"
558+
/>
559+
<span>{{ resource.comments_count ?? 0 }} comments</span>
560+
</Link>
548561
</div>
549562

550563
<!-- Right: Clean Share Button (Exactly matching Forum & Blog) -->

0 commit comments

Comments
 (0)