Merge pull request 'api detail exercise' (#4) from feature/api-detail-exercise into developer
Reviewed-on: #4pull/1/head
commit
11b4605861
12 changed files with 206 additions and 4 deletions
@ -0,0 +1,24 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class BlankResource extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @return array<string, mixed> |
||||
*/ |
||||
public function toArray(Request $request): array |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'position' => $this->position, |
||||
'correct_answer' => $this->correct_answer, |
||||
'other_answers' => $this->other_answers, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class ChoiceResource extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @return array<string, mixed> |
||||
*/ |
||||
public function toArray(Request $request): array |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'content' => $this->content, |
||||
'is_correct' => $this->is_correct, |
||||
'position' => $this->position, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class ExerciseResource extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @return array<string, mixed> |
||||
*/ |
||||
public function toArray(Request $request): array |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'name' => $this->lesson_name, |
||||
'description' => $this->description, |
||||
'level' => $this->level_label, |
||||
'year' => $this->year, |
||||
'skills' => SkillResource::collection($this->whenLoaded('skills')), |
||||
'question_groups' => QuestionGroupResource::collection($this->whenLoaded('questionGroups')), |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class QuestionGroupResource extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @return array<string, mixed> |
||||
*/ |
||||
public function toArray(Request $request): array |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'content' => $this->content, |
||||
'questions' => QuestionResource::collection($this->whenLoaded('questions')), |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class QuestionResource extends JsonResource |
||||
{ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'content' => $this->content, |
||||
'score' => $this->score, |
||||
'explanation' => $this->explanation, |
||||
'hint' => $this->hint, |
||||
'type' => [ |
||||
'code' => $this->type->code ?? null, |
||||
'name' => $this->type->name ?? null, |
||||
], |
||||
'choices' => $this->when($this->type->code === 'multiple_choice', ChoiceResource::collection($this->choices)), |
||||
'blanks' => $this->when($this->type->code !== 'multiple_choice', BlankResource::collection($this->blanks)), |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class SkillResource extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @return array<string, mixed> |
||||
*/ |
||||
public function toArray(Request $request): array |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'name' => $this->name |
||||
]; |
||||
} |
||||
} |
Loading…
Reference in new issue