2021-10-28 10:51:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
use common\models\UserResponse;
|
2022-03-15 16:54:34 +03:00
|
|
|
use common\services\UserResponseService;
|
2021-10-28 10:51:14 +03:00
|
|
|
use Yii;
|
2021-11-12 14:30:01 +03:00
|
|
|
use yii\base\InvalidConfigException;
|
2021-10-28 10:51:14 +03:00
|
|
|
use yii\web\BadRequestHttpException;
|
|
|
|
use yii\web\ServerErrorHttpException;
|
|
|
|
|
2022-03-11 14:37:44 +03:00
|
|
|
class UserResponseController extends ApiController
|
2021-10-28 10:51:14 +03:00
|
|
|
{
|
|
|
|
public function verbs(): array
|
|
|
|
{
|
|
|
|
return [
|
2021-11-12 14:30:01 +03:00
|
|
|
'set-response' => ['post'],
|
2021-11-15 12:57:21 +03:00
|
|
|
'set-responses' => ['post'],
|
2021-10-28 10:51:14 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-11-12 14:30:01 +03:00
|
|
|
/**
|
|
|
|
* @throws InvalidConfigException
|
2022-03-15 16:54:34 +03:00
|
|
|
* @throws ServerErrorHttpException|BadRequestHttpException
|
2021-11-12 14:30:01 +03:00
|
|
|
*/
|
2022-03-15 16:54:34 +03:00
|
|
|
public function actionSetResponse(): UserResponse
|
2021-10-28 10:51:14 +03:00
|
|
|
{
|
2022-03-15 16:54:34 +03:00
|
|
|
$userResponseModel = UserResponseService::createUserResponse(Yii::$app->getRequest()->getBodyParams());
|
|
|
|
if ($userResponseModel->errors) {
|
|
|
|
throw new ServerErrorHttpException(json_encode($userResponseModel->errors));
|
|
|
|
}
|
|
|
|
return $userResponseModel;
|
2021-11-15 12:57:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws InvalidConfigException
|
2022-03-15 16:54:34 +03:00
|
|
|
* @throws ServerErrorHttpException|BadRequestHttpException
|
2021-11-15 12:57:21 +03:00
|
|
|
*/
|
|
|
|
public function actionSetResponses(): array
|
|
|
|
{
|
2022-03-15 16:54:34 +03:00
|
|
|
$userResponseModels = UserResponseService::createUserResponses(Yii::$app->getRequest()->getBodyParams());
|
|
|
|
foreach ($userResponseModels as $model) {
|
|
|
|
if ($model->errors) {
|
|
|
|
throw new ServerErrorHttpException(json_encode($model->errors));
|
|
|
|
}
|
2021-10-28 10:51:14 +03:00
|
|
|
}
|
2022-03-15 16:54:34 +03:00
|
|
|
return $userResponseModels;
|
2021-10-28 10:51:14 +03:00
|
|
|
}
|
|
|
|
}
|