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

63 lines
2.2 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserTestResource extends JsonResource
{
/**
* @OA\Schema(
* schema="UserTestResource",
* type="object",
* title="UserTest",
* properties={
* @OA\Property(property="id", type="integer", example=1),
*
* @OA\Property(property="test_id", type="integer", example=5),
* @OA\Property(property="test", ref="#/components/schemas/TestResource"),
*
* @OA\Property(property="user_id", type="integer", example=10),
* @OA\Property(property="user", ref="#/components/schemas/UserResource"),
*
* @OA\Property(property="closed_at", type="string", format="date-time", example="2025-12-01T23:59:59Z"),
* @OA\Property(property="is_completed", type="boolean", example=false),
* @OA\Property(property="score", type="integer", example=85),
* @OA\Property(property="is_available", type="boolean", example=true),
*
* @OA\Property(
* property="answers",
* type="array",
* @OA\Items(ref="#/components/schemas/UserTestAnswerResource")
* ),
*
* @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,
'test_id' => $this->test_id,
'test' => new TestResource($this->whenLoaded('test')),
'user_id' => $this->user_id,
'user' => new UserResource($this->whenLoaded('user')),
'closed_at' => $this->closed_at,
'is_completed' => $this->is_completed,
'score' => $this->score,
'is_available' => $this->isAvailable(),
'answers' => UserTestAnswerResource::collection($this->whenLoaded('answers')),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}