add some api method
This commit is contained in:
@ -8,7 +8,7 @@ use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class AnswerController extends ApiController
|
||||
class AnswerController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
|
63
frontend/modules/api/controllers/DocumentController.php
Normal file
63
frontend/modules/api/controllers/DocumentController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Document;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
// 'get-task' => ['get'],
|
||||
'get-document-list' => ['get'],
|
||||
// 'create-task' => ['post'],
|
||||
// 'update-task' => ['put', 'patch'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionGetDocumentList(): array
|
||||
{
|
||||
$documents = Document::find()->select(['id','title', 'manager_id'])->all();
|
||||
|
||||
if(empty($documents)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
}
|
||||
|
||||
return $documents;
|
||||
}
|
||||
|
||||
public function actionGetDocument(): array
|
||||
{
|
||||
$document_id = Yii::$app->request->get('document_id');
|
||||
if(empty($document_id) or !is_numeric($document_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect document ID');
|
||||
}
|
||||
|
||||
$document = Document::find()
|
||||
->where(['document.id' => $document_id])
|
||||
->all();
|
||||
|
||||
if(empty($document)) {
|
||||
throw new NotFoundHttpException('There is no such document');
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Document;
|
||||
use common\models\DocumentFieldValue;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class DocumentFieldValueController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
// 'get-task' => ['get'],
|
||||
'document-field-value-list' => ['get'],
|
||||
// 'create-task' => ['post'],
|
||||
// 'update-task' => ['put', 'patch'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionDocumentFieldValueList(): array
|
||||
{
|
||||
$document_id = Yii::$app->request->get('document_id');
|
||||
if(empty($document_id) or !is_numeric($document_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect document ID');
|
||||
}
|
||||
|
||||
$fieldValues = DocumentFieldValue::find()
|
||||
->where(['document_id' => $document_id])
|
||||
->all();
|
||||
|
||||
if(empty($fieldValues)) {
|
||||
throw new NotFoundHttpException('There is no such fields');
|
||||
}
|
||||
|
||||
return $fieldValues;
|
||||
}
|
||||
}
|
@ -9,8 +9,9 @@ use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class ManagerController extends ApiController
|
||||
class ManagerController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class QuestionController extends ApiController
|
||||
class QuestionController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class TaskController extends ApiController
|
||||
class TaskController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ use yii\rest\Controller;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class TaskUserController extends ApiController
|
||||
class TaskUserController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class UserQuestionnaireController extends ApiController
|
||||
class UserQuestionnaireController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
|
Reference in New Issue
Block a user