Created API endpoints

This commit is contained in:
2017-12-20 16:45:20 +07:00
parent ad11643854
commit 554c74481b
53 changed files with 4637 additions and 9 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class AnswerResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'choice' => $this->questionchoice,
'text' => $this->text,
'links' => [
'self' => route('answers.show', ['answers' => $this->id]),
'relatedTo' => [
'question' => route('questions.show', ['questions' => $this->question_id]),
'respondent' => route('respondents.show', ['respondents' => $this->respondent_id])
]
]
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class CategoryResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
// return parent::toArray($request);
return [
'id' => $this->id,
'name' => $this->name,
'code' => $this->code,
'links' => [
'self' => route('categories.show', ['categories' => $this->id])
]
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class QuestionResource extends Resource
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
// return parent::toArray($request);
return [
'id' => $this->id,
'text' => $this->text,
'number' => $this->number,
'description' => $this->description,
'section' => new SectionResource($this->section),
'links' => [
'self' => route('questions.show', ['questions' => $this->id])
]
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class QuestionchoiceResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'number' => $this->number,
'text' => $this->text,
'fillable' => $this->fillable,
'description' => $this->description,
'links' => [
'relatedTo' => route('questions.show', ['questions' => $this->question_id])
]
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class QuestionnaireResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
// return parent::toArray($request);
return [
'id' => $this->id,
'category' => new CategoryResource($this->category),
'title' => $this->title,
'description' => $this->description,
'links' => [
'self' => route('questionnaires.show', ['questionnaires' => $this->id])
]
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class RespondentResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'occupation' => $this->occupation,
'gender' => $this->gender,
'links' => [
'self' => route('respondents.show', ['respondents' => $this->id])
]
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class SectionResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
// return parent::toArray($request);
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'links' => [
'self' => route('sections.show', ['sections' => $this->id])
]
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class UserResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
// return parent::toArray($request);
return [
'id' => $this->id,
'username' => $this->username,
'name' => $this->name,
'email' => $this->email
];
}
}