HoshiAI-be/app/Http/Resources/UserTestAnswerResource.php
2025-11-12 23:04:55 +01:00

55 lines
1.9 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserTestAnswerResource extends JsonResource
{
/**
* @OA\Schema(
* schema="UserTestAnswerResource",
* type="object",
* title="UserTestAnswer",
* properties={
* @OA\Property(property="id", type="integer", example=1),
*
* @OA\Property(property="user_test_id", type="integer", example=5),
*
* @OA\Property(property="question_id", type="integer", example=12),
* @OA\Property(property="question", ref="#/components/schemas/QuestionResource"),
*
* @OA\Property(property="answer", type="array", @OA\Items(type="string"), example={"42","43"}),
*
* @OA\Property(property="user_id", type="integer", example=10),
* @OA\Property(property="user", ref="#/components/schemas/UserResource"),
*
* @OA\Property(property="is_correct", type="boolean", example=true),
* @OA\Property(property="created_at", type="string", format="date-time", example="2025-11-11T20:39:22Z"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-11-11T20:39:22Z")
* }
* )
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'user_test_id' => $this->user_test_id,
'question_id' => $this->question_id,
'question' => new QuestionResource($this->whenLoaded('question')),
'answer' => $this->answer,
'user_id' => $this->user_id,
'user' => new UserResource($this->whenLoaded('user')),
'is_correct' => $this->isCorrect(),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}