From a056603d432282b99236aa4bfc082fb3e2c1646f Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 17:29:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`refacto?= =?UTF-8?q?r/eager-loading-count`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @kvostyc. * https://github.com/supo-dev/api/pull/9#issuecomment-3366580620 The following files were modified: * `app/Http/Controllers/UserController.php` --- app/Http/Controllers/UserController.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 03c288a..d44bbae 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -16,17 +16,30 @@ final readonly class UserController { + /** + * Provide a JSON representation of a user including relationship counts. + * + * The response payload contains the user's id, username, email, a boolean + * `email_verified` flag (true if `email_verified_at` is not null), + * `created_at` as an ISO 8601 string, and preloaded counts for `posts`, + * `followers`, and `following`. + * + * @param User $user The user model to present (counts for posts, followers, and following are preloaded). + * @return JsonResponse JSON object with keys: `id`, `username`, `email`, `email_verified`, `created_at`, `posts_count`, `followers_count`, and `following_count`. + */ public function show(User $user): JsonResponse { + $user->loadCount(['posts', 'followers', 'following']); + return response()->json([ 'id' => $user->id, 'username' => $user->username, 'email' => $user->email, 'email_verified' => $user->email_verified_at !== null, 'created_at' => $user->created_at->toISOString(), - 'posts_count' => $user->posts()->count(), - 'followers_count' => $user->followers()->count(), - 'following_count' => $user->following()->count(), + 'posts_count' => $user->posts_count, + 'followers_count' => $user->followers_count, + 'following_count' => $user->following_count, ]); } @@ -64,4 +77,4 @@ public function destroy( return response(status: 204); } -} +} \ No newline at end of file