profileService = new UserProfileService(); $this->statsService = new UserStatsService(); } /** * Identity plus totals in one call — the profile header needs both, and * two round trips would leave the name and the numbers popping in * separately. */ public function profile(GetUserProfileRequest $request) { // Accepts a slug or an id; everything downstream works in ids. $userId = UserProfileService::resolveId($request->id); $profile = $this->profileService->profile($userId); if ($profile === null) { return Response::error(__('User not found.', 'bit-connect'))->httpStatus(self::HTTP_NOT_FOUND); } return Response::success( [ 'user' => $profile, 'stats' => $this->statsService->forUser($userId), ] ); } public function topics(GetUserContentRequest $request) { if ($this->profileService->profile((int) $request->id) === null) { return Response::error(__('User not found.', 'bit-connect'))->httpStatus(self::HTTP_NOT_FOUND); } return Response::success( $this->profileService->topics( (int) $request->id, (int) ($request->page ?? 1), (int) ($request->per_page ?? 10) ) ); } public function comments(GetUserContentRequest $request) { if ($this->profileService->profile((int) $request->id) === null) { return Response::error(__('User not found.', 'bit-connect'))->httpStatus(self::HTTP_NOT_FOUND); } return Response::success( $this->profileService->comments( (int) $request->id, (int) ($request->page ?? 1), (int) ($request->per_page ?? 10) ) ); } public function overview(GetUserContentRequest $request) { if ($this->profileService->profile((int) $request->id) === null) { return Response::error(__('User not found.', 'bit-connect'))->httpStatus(self::HTTP_NOT_FOUND); } return Response::success( $this->profileService->overview( (int) $request->id, (int) ($request->page ?? 1), (int) ($request->per_page ?? 10) ) ); } public function insights(GetUserInsightsRequest $request) { if ($this->profileService->profile((int) $request->id) === null) { return Response::error(__('User not found.', 'bit-connect'))->httpStatus(self::HTTP_NOT_FOUND); } return Response::success( (new UserInsightsService())->forUser((int) $request->id, $request->period ?? '30d') ); } public function permissions(GetUserPermissionsRequest $request) { $permissions = $this->profileService->permissions((int) $request->id); if ($permissions === []) { return Response::error(__('User not found.', 'bit-connect'))->httpStatus(self::HTTP_NOT_FOUND); } return Response::success(['permissions' => $permissions]); } public function votes(GetUserVotesRequest $request) { return Response::success( $this->profileService->votedTopics( (int) $request->id, (int) ($request->page ?? 1), (int) ($request->per_page ?? 10) ) ); } }