diff --git a/common/services/ProfileService.php b/common/services/ProfileService.php index bd90b60..909e07f 100644 --- a/common/services/ProfileService.php +++ b/common/services/ProfileService.php @@ -16,11 +16,11 @@ class ProfileService /** * @throws ServerErrorHttpException */ - public static function getMainData($user_id)//: array + public static function getMainData($user_id): array { $userCard = UserCard::findOne(['id_user' => $user_id]); if (empty($userCard)) { - throw new ServerErrorHttpException(json_encode('Profile not found!')); + throw new ServerErrorHttpException('Profile not found!'); } return array('fio' => $userCard->fio, 'photo' => $userCard->photo, @@ -31,10 +31,7 @@ class ProfileService 'position_name' => $userCard->position->name); } - /** - * @throws BadRequestHttpException - */ - public static function getProfile($id, $request)//: ?array + public static function getProfile($id, $request): ?array { $searchModel = new ProfileSearchForm(); $searchModel->attributes = $request; @@ -46,7 +43,7 @@ class ProfileService } /** - * @throws BadRequestHttpException + * @throws ServerErrorHttpException */ public static function getProfileWithReportPermission($user_card_id): ?array { @@ -59,7 +56,7 @@ class ProfileService self::addPermission($profile, $user_card_id); return $profile; } - throw new BadRequestHttpException(json_encode('There is no user with this id')); + throw new ServerErrorHttpException('There is no user with this id'); } private static function addPermission(&$profile, $user_card_id) diff --git a/common/services/UserQuestionnaireService.php b/common/services/UserQuestionnaireService.php index c5cfa3d..a21410b 100644 --- a/common/services/UserQuestionnaireService.php +++ b/common/services/UserQuestionnaireService.php @@ -51,7 +51,7 @@ class UserQuestionnaireService { $userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]); if (empty($userQuestionnaireModel)) { - throw new ServerErrorHttpException(json_encode('Not found UserQuestionnaire')); + throw new ServerErrorHttpException('Not found UserQuestionnaire'); } $count = Question::find() ->where(['questionnaire_id' => $userQuestionnaireModel->questionnaire_id]) @@ -67,7 +67,7 @@ class UserQuestionnaireService { $userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]); if (empty($userQuestionnaireModel)) { - throw new ServerErrorHttpException(json_encode('Not found UserQuestionnaire')); + throw new ServerErrorHttpException('Not found UserQuestionnaire'); } $pointSum = Question::find() ->where(['questionnaire_id' => $userQuestionnaireModel->questionnaire_id]) diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 70c3a7c..c6e9a4f 100755 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -3,22 +3,46 @@ namespace frontend\modules\api\controllers; use common\services\ProfileService; +use yii\helpers\ArrayHelper; use yii\web\BadRequestHttpException; +use yii\web\NotFoundHttpException; use yii\web\ServerErrorHttpException; class ProfileController extends ApiController { - public function verbs(): array +// public function verbs(): array +// { +// return [ +// '' => ['get'], +// 'profile-with-report-permission' => ['post', 'patch'] +// ]; +// } + + public function behaviors(): array { - return [ - '' => ['get'], - 'profile-with-report-permission' => ['post', 'patch'] - ]; + return ArrayHelper::merge(parent::behaviors(), [ + + 'verbs' => [ + 'class' => \yii\filters\VerbFilter::class, + 'actions' => [ + '' => ['get'], + 'profile-with-report-permission' => ['post', 'patch'], + 'get-main-data' => ['get'] + ], + ] + ]); } + /** + * @throws NotFoundHttpException + */ public function actionIndex($id = null): ?array { - return ProfileService::getProfile($id, \Yii::$app->request->get()); + $profiles = ProfileService::getProfile($id, \Yii::$app->request->get()); + if(empty($profiles)) { + throw new NotFoundHttpException('Profiles not found'); + } + return $profiles; } /** diff --git a/frontend/modules/api/controllers/UserQuestionnaireController.php b/frontend/modules/api/controllers/UserQuestionnaireController.php index 3a2c875..a434170 100644 --- a/frontend/modules/api/controllers/UserQuestionnaireController.php +++ b/frontend/modules/api/controllers/UserQuestionnaireController.php @@ -3,17 +3,27 @@ namespace frontend\modules\api\controllers; use common\services\UserQuestionnaireService; +use yii\helpers\ArrayHelper; use yii\web\NotFoundHttpException; use yii\web\ServerErrorHttpException; class UserQuestionnaireController extends ApiController { - public function verbs() + + public function behaviors(): array { - return [ - 'questionnaires-list' => ['get'], - 'questionnaire-completed' => ['get'], - ]; + return ArrayHelper::merge(parent::behaviors(), [ + + 'verbs' => [ + 'class' => \yii\filters\VerbFilter::class, + 'actions' => [ + 'questionnaires-list' => ['get'], + 'questionnaire-completed' => ['get'], + 'get-points-number' => ['get'], + 'get-question-number' => ['get'], + ], + ] + ]); } /** @@ -39,7 +49,7 @@ class UserQuestionnaireController extends ApiController { $userQuestionnaireModel = UserQuestionnaireService::calculateScore($user_questionnaire_uuid); if ($userQuestionnaireModel->errors) { - throw new ServerErrorHttpException(json_encode($userQuestionnaireModel->errors)); + throw new ServerErrorHttpException($userQuestionnaireModel->errors); } return $userQuestionnaireModel; } @@ -51,7 +61,7 @@ class UserQuestionnaireController extends ApiController { $questionPointsNumber = UserQuestionnaireService::getPointsNumber($user_questionnaire_uuid); if (empty($questionPointsNumber)) { - throw new ServerErrorHttpException(json_encode('Question points not found!')); + throw new ServerErrorHttpException('Question points not found!'); } return $questionPointsNumber; } @@ -63,7 +73,7 @@ class UserQuestionnaireController extends ApiController { $questionNumber = UserQuestionnaireService::getQuestionNumber($user_questionnaire_uuid); if (empty($questionNumber)) { - throw new ServerErrorHttpException(json_encode('Question number not found!')); + throw new ServerErrorHttpException('Question number not found!'); } return $questionNumber; } diff --git a/frontend/modules/api/models/ProfileSearchForm.php b/frontend/modules/api/models/ProfileSearchForm.php index e9d0f09..b7ca82f 100755 --- a/frontend/modules/api/models/ProfileSearchForm.php +++ b/frontend/modules/api/models/ProfileSearchForm.php @@ -86,7 +86,7 @@ class ProfileSearchForm extends Model $model->andWhere(['status' => [4, 12]]); $model->andWhere(['deleted_at' => null]); - $model->groupBy('card_skill.card_id'); + //$model->groupBy('card_skill.card_id'); $res = $model->limit($this->limit) ->offset($this->offset)->orderBy('updated_at DESC')->asArray()->all();