2021-10-28 10:51:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
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-15 12:57:21 +03:00
|
|
|
/**
|
2023-10-10 15:06:01 +03:00
|
|
|
* @OA\Post(path="/user-response/set-responses",
|
|
|
|
* summary="Добавить массив ответов пользователя",
|
|
|
|
* description="Добавление массива ответов на вопросы от пользователя",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"Tests"},
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/x-www-form-urlencoded",
|
|
|
|
* @OA\Schema(
|
|
|
|
* required={"request_id"},
|
|
|
|
* @OA\Property(
|
|
|
|
* property="user_id",
|
|
|
|
* type="integer",
|
|
|
|
* description="Идентификатор пользователя",
|
|
|
|
* nullable=false,
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="question_id",
|
|
|
|
* type="integer",
|
|
|
|
* description="Идентификатор вопроса",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="response_body",
|
|
|
|
* type="string",
|
|
|
|
* description="UUID анкеты назначенной пользователю",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="user_questionnaire_uuid",
|
|
|
|
* type="string",
|
|
|
|
* description="UUID анкеты назначенной пользователю",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
*
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает объект Запроса",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(ref="#/components/schemas/UserResponseExampleArr"),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
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
|
|
|
}
|
|
|
|
}
|