Forum: - TipTap WYSIWYG editor with full toolbar - @emoji-mart/react emoji picker (consistent with tweets) - @mention autocomplete with user search API - Fix PHP 8.4 parse errors in Blade templates - Fix thread data display (paginator items) - Align forum page widths to max-w-5xl Discover: - Extract shared _nav.blade.php partial - Add missing nav links to for-you page - Add Following link for authenticated users Feed/Posts: - Post model, controllers, policies, migrations - Feed page components (PostComposer, FeedCard, etc) - Post reactions, comments, saves, reports, sharing - Scheduled publishing support - Link preview controller Profile: - Profile page components (ProfileHero, ProfileTabs) - Profile API controller Uploads: - Upload wizard enhancements - Scheduled publish picker - Studio status bar and readiness checklist
61 lines
2.5 KiB
PHP
61 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Posts;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Services\Posts\PostFeedService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PostFeedController extends Controller
|
|
{
|
|
public function __construct(private PostFeedService $feedService) {}
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
// Profile feed — GET /api/posts/profile/{username}
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
|
|
public function profile(Request $request, string $username): JsonResponse
|
|
{
|
|
$profileUser = User::where('username', $username)->firstOrFail();
|
|
$viewerId = $request->user()?->id;
|
|
$page = max(1, (int) $request->query('page', 1));
|
|
|
|
$paginated = $this->feedService->getProfileFeed($profileUser, $viewerId, $page);
|
|
|
|
$formatted = collect($paginated['data'])
|
|
->map(fn ($post) => $this->feedService->formatPost($post, $viewerId))
|
|
->values();
|
|
|
|
return response()->json([
|
|
'data' => $formatted,
|
|
'meta' => $paginated['meta'],
|
|
]);
|
|
}
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
// Following feed — GET /api/posts/following
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
|
|
public function following(Request $request): JsonResponse
|
|
{
|
|
$user = $request->user();
|
|
$page = max(1, (int) $request->query('page', 1));
|
|
$filter = $request->query('filter', 'all');
|
|
|
|
$result = $this->feedService->getFollowingFeed($user, $page, $filter);
|
|
|
|
$viewerId = $user->id;
|
|
$formatted = array_map(
|
|
fn ($post) => $this->feedService->formatPost($post, $viewerId),
|
|
$result['data'],
|
|
);
|
|
|
|
return response()->json([
|
|
'data' => $formatted,
|
|
'meta' => $result['meta'],
|
|
]);
|
|
}
|
|
}
|