trypost/app/Http/Resources/Api/PostPlatformResource.php
Paulo Castellano ce6ee04883 Bring post platform meta (aspect ratio) to parity across API and MCP
PR #82 made `meta.aspect_ratio` crop Facebook (and already Instagram) feed
images at publish time, but the API and MCP surfaces only half-supported it:
you couldn't set meta at creation, the value wasn't validated, and responses
never returned it. This closes those gaps.

- New `AspectRatio` enum is the single source of truth for the allowed ratios
  (1:1, 4:5, 16:9, original). App/API/MCP requests now validate via
  `Rule::enum(AspectRatio::class)` — an invalid ratio is rejected everywhere
  instead of silently center-cropping to square.
- API `StorePostRequest` and MCP `CreatePostTool` now accept `platforms.*.meta`;
  `CreatePost` persists it. MCP create documents `meta` in its schema.
- `Api\PostPlatformResource` now exposes `meta`, so API and MCP responses return
  the aspect_ratio (and other per-platform meta) a client set.
2026-06-10 15:36:47 -03:00

35 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources\Api;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PostPlatformResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'platform' => $this->platform?->value,
'content_type' => $this->content_type?->value,
'meta' => $this->meta,
'status' => $this->status?->value,
'enabled' => $this->enabled,
'platform_url' => $this->platform_url,
'published_at' => $this->published_at?->format('Y-m-d H:i:s'),
'error_message' => $this->error_message,
// Display fields fall back to snapshots (platform_name/username/avatar)
// so deleted accounts still render correctly in the post history.
'display_name' => $this->display_name,
'display_username' => $this->display_username,
'display_avatar' => $this->display_avatar,
'social_account' => new SocialAccountResource($this->whenLoaded('socialAccount')),
];
}
}