- 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)
77 lines
1.9 KiB
PHP
77 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PostPlatform\ContentType;
|
|
use App\Enums\SocialAccount\Platform as SocialPlatform;
|
|
use App\Models\Traits\HasMedia;
|
|
use Database\Factories\PostPlatformFactory;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class PostPlatform extends Model
|
|
{
|
|
/** @use HasFactory<PostPlatformFactory> */
|
|
use HasFactory, HasMedia, HasUuids;
|
|
|
|
protected $fillable = [
|
|
'post_id',
|
|
'social_account_id',
|
|
'enabled',
|
|
'platform',
|
|
'content',
|
|
'content_type',
|
|
'status',
|
|
'platform_post_id',
|
|
'platform_url',
|
|
'error_message',
|
|
'published_at',
|
|
'meta',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'enabled' => 'boolean',
|
|
'platform' => SocialPlatform::class,
|
|
'content_type' => ContentType::class,
|
|
'published_at' => 'datetime',
|
|
'meta' => 'array',
|
|
];
|
|
}
|
|
|
|
public function post(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Post::class);
|
|
}
|
|
|
|
public function socialAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SocialAccount::class);
|
|
}
|
|
|
|
public function markAsPublishing(): void
|
|
{
|
|
$this->update(['status' => 'publishing']);
|
|
}
|
|
|
|
public function markAsPublished(string $platformPostId, ?string $platformUrl = null): void
|
|
{
|
|
$this->update([
|
|
'status' => 'published',
|
|
'platform_post_id' => $platformPostId,
|
|
'platform_url' => $platformUrl,
|
|
'published_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function markAsFailed(string $errorMessage): void
|
|
{
|
|
$this->update([
|
|
'status' => 'failed',
|
|
'error_message' => $errorMessage,
|
|
]);
|
|
}
|
|
}
|