feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
2026-07-25 01:00:07 +00:00
|
|
|
use App\Actions\SocialAccount\ListDiscordChannels;
|
2026-07-25 00:47:51 +00:00
|
|
|
use App\Actions\SocialAccount\ListPinterestBoards;
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
use App\Actions\SocialAccount\ToggleSocialAccount;
|
2026-07-25 00:47:51 +00:00
|
|
|
use App\Enums\SocialAccount\Platform;
|
2026-07-25 01:00:07 +00:00
|
|
|
use App\Exceptions\PlatformUnavailableException;
|
|
|
|
|
use App\Exceptions\Social\ErrorCategory;
|
|
|
|
|
use App\Exceptions\Social\PinterestPublishException;
|
|
|
|
|
use App\Exceptions\TokenExpiredException;
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
use App\Http\Resources\Api\SocialAccountResource;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
|
|
class SocialAccountController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(Request $request): AnonymousResourceCollection
|
|
|
|
|
{
|
2026-05-03 21:38:17 +00:00
|
|
|
$accounts = $request->user()->currentWorkspace->socialAccounts()->orderBy('platform')->get();
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
|
|
|
|
|
return SocialAccountResource::collection($accounts);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-25 01:09:35 +00:00
|
|
|
public function toggle(Request $request, SocialAccount $account): SocialAccountResource
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
{
|
2026-07-25 01:09:35 +00:00
|
|
|
$this->authorize('view', $account);
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
|
|
|
|
|
ToggleSocialAccount::execute($account);
|
|
|
|
|
|
|
|
|
|
return new SocialAccountResource($account);
|
|
|
|
|
}
|
2026-07-25 00:47:51 +00:00
|
|
|
|
|
|
|
|
public function boards(Request $request, SocialAccount $account): JsonResponse
|
|
|
|
|
{
|
2026-07-25 01:09:35 +00:00
|
|
|
$this->authorize('view', $account);
|
2026-07-25 00:47:51 +00:00
|
|
|
|
|
|
|
|
if ($account->platform !== Platform::Pinterest) {
|
|
|
|
|
return response()->json(
|
|
|
|
|
['message' => 'Boards are only available for Pinterest accounts.'],
|
|
|
|
|
Response::HTTP_UNPROCESSABLE_ENTITY,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-25 01:00:07 +00:00
|
|
|
try {
|
2026-07-25 01:49:04 +00:00
|
|
|
return response()->json(ListPinterestBoards::execute($account));
|
2026-07-25 01:00:07 +00:00
|
|
|
} 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
|
|
|
|
|
{
|
2026-07-25 01:09:35 +00:00
|
|
|
$this->authorize('view', $account);
|
2026-07-25 01:00:07 +00:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
};
|
2026-07-25 00:47:51 +00:00
|
|
|
}
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
}
|