HoshiAI-be/app/Http/Resources/TestResource.php
2025-11-13 12:05:08 +01:00

60 lines
2.3 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TestResource extends JsonResource
{
/**
* @OA\Schema(
* schema="TestResource",
* type="object",
* title="Test",
* description="Test resource",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="title", type="string", example="Sample Test"),
* @OA\Property(property="description", type="string", nullable=true, example="Optional description"),
*
* @OA\Property(property="category_id", type="integer", nullable=true, example=3),
* @OA\Property(property="category", ref="#/components/schemas/CategoryResource"),
*
* @OA\Property(
* property="questions",
* type="array",
* @OA\Items(ref="#/components/schemas/QuestionResource")
* ),
*
* @OA\Property(property="is_available", type="boolean", example=true),
* @OA\Property(property="author_id", type="integer", nullable=true, example=2),
* @OA\Property(property="author", ref="#/components/schemas/UserResource"),
*
* @OA\Property(property="closed_at", type="string", format="date-time", nullable=true, example="2025-11-11T10:30:00Z"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2025-11-11T10:00:00Z"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-11-11T10:15:00Z")
* )
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'category_id' => $this->category_id,
'category' => new CategoryResource($this->whenLoaded('category')),
'questions' => QuestionResource::collection($this->whenLoaded('questions')),
'is_available' => $this->isAvailable(),
'author_id' => $this->author_id,
'author' => new UserResource($this->whenLoaded('author')),
'closed_at' => $this->closed_at,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}