user()->currentWorkspace->socialAccounts()->orderBy('platform')->get(); return SocialAccountResource::collection($accounts); } public function toggle(Request $request, SocialAccount $account): SocialAccountResource { $this->authorize('view', $account); ToggleSocialAccount::execute($account); return new SocialAccountResource($account); } public function boards(Request $request, SocialAccount $account): JsonResponse { $this->authorize('view', $account); if ($account->platform !== Platform::Pinterest) { return response()->json( ['message' => 'Boards are only available for Pinterest accounts.'], Response::HTTP_UNPROCESSABLE_ENTITY, ); } try { return response()->json(ListPinterestBoards::execute($account)); } catch (TokenExpiredException $e) { return response()->json( ['message' => $e->getMessage()], Response::HTTP_UNAUTHORIZED, ); } catch (PinterestPublishException $e) { return response()->json( ['message' => $e->userMessage], $this->statusForPinterestCategory($e->category), ); } } public function channels(Request $request, SocialAccount $account): JsonResponse { $this->authorize('view', $account); if ($account->platform !== Platform::Discord) { return response()->json( ['message' => 'Channels are only available for Discord accounts.'], Response::HTTP_UNPROCESSABLE_ENTITY, ); } try { return response()->json([ 'channels' => ListDiscordChannels::execute($account), ]); } catch (PlatformUnavailableException $e) { return response()->json( ['message' => $e->getMessage()], Response::HTTP_BAD_GATEWAY, ); } } private function statusForPinterestCategory(ErrorCategory $category): int { return match ($category) { ErrorCategory::RateLimit => Response::HTTP_TOO_MANY_REQUESTS, ErrorCategory::Permission => Response::HTTP_FORBIDDEN, default => Response::HTTP_BAD_GATEWAY, }; } }