trypost/database/factories/PostPlatformFactory.php
Paulo Castellano 8689e54e55 refactor: restructure to Actions, subdomain routes (app/api), API tokens
- Extract business logic from controllers into Action classes:
  Post/, Workspace/, Hashtag/, Label/, Invite/, ApiKey/
- Create subdomain routing: app.trypost.test (Inertia dashboard),
  api.trypost.test (REST API with token auth)
- Add ApiToken model with tp_ prefix, token_lookup/hash auth
- Add AuthenticateApiToken middleware for API authentication
- Create Api controllers with JSON Resources for all entities
- Create App controllers that use Actions + Inertia responses
- Organize Form Requests into Api/ and App/ directories
- Add api_tokens migration
- Update all route names with app. prefix
- Update all tests to use new route names (684 passing)
2026-03-29 19:24:28 -03:00

170 lines
4.4 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\PostPlatform\ContentType;
use App\Enums\SocialAccount\Platform;
use App\Models\Post;
use App\Models\PostPlatform;
use App\Models\SocialAccount;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<PostPlatform>
*/
class PostPlatformFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'post_id' => Post::factory(),
'social_account_id' => SocialAccount::factory(),
'enabled' => true,
'platform' => Platform::LinkedIn,
'content' => $this->faker->paragraph(),
'content_type' => ContentType::LinkedInPost,
'status' => 'pending',
'meta' => [],
];
}
public function disabled(): static
{
return $this->state(fn (array $attributes) => [
'enabled' => false,
]);
}
public function published(): static
{
return $this->state(fn (array $attributes) => [
'status' => 'published',
'platform_post_id' => $this->faker->uuid(),
'platform_url' => $this->faker->url(),
'published_at' => now(),
]);
}
public function failed(): static
{
return $this->state(fn (array $attributes) => [
'status' => 'failed',
'error_message' => 'Failed to publish',
]);
}
public function linkedin(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::LinkedIn,
]);
}
public function x(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::X,
'content_type' => ContentType::XPost,
]);
}
public function instagram(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Instagram,
]);
}
public function bluesky(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Bluesky,
'content_type' => ContentType::BlueskyPost,
]);
}
public function mastodon(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Mastodon,
'content_type' => ContentType::MastodonPost,
]);
}
public function threads(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Threads,
'content_type' => ContentType::ThreadsPost,
]);
}
public function tiktok(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::TikTok,
'content_type' => ContentType::TikTokVideo,
]);
}
public function youtube(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::YouTube,
'content_type' => ContentType::YouTubeShort,
]);
}
public function pinterest(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Pinterest,
'content_type' => ContentType::PinterestPin,
]);
}
public function pinterestVideoPin(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Pinterest,
'content_type' => ContentType::PinterestVideoPin,
]);
}
public function pinterestCarousel(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Pinterest,
'content_type' => ContentType::PinterestCarousel,
]);
}
public function facebook(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Facebook,
'content_type' => ContentType::FacebookPost,
]);
}
public function facebookReel(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Facebook,
'content_type' => ContentType::FacebookReel,
]);
}
public function facebookStory(): static
{
return $this->state(fn (array $attributes) => [
'platform' => Platform::Facebook,
'content_type' => ContentType::FacebookStory,
]);
}
}