diff --git a/common/services/ProfileService.php b/common/services/ProfileService.php index 4e13366..fc47886 100644 --- a/common/services/ProfileService.php +++ b/common/services/ProfileService.php @@ -8,13 +8,32 @@ use common\models\UserCard; use frontend\modules\api\models\ProfileSearchForm; use Yii; use yii\web\BadRequestHttpException; +use yii\web\ServerErrorHttpException; class ProfileService { + /** + * @throws ServerErrorHttpException + */ + public static function getMainData($user_id): array + { + $userCard = UserCard::findOne(['id_user' => $user_id]); + if (empty($userCard)) { + throw new ServerErrorHttpException(json_encode($userCard->errors)); + } + return array('fio' => $userCard->fio, + 'photo' => $userCard->photo, + 'gender' => $userCard->gender, + 'level' => $userCard->level, + 'years_of_exp' => $userCard->years_of_exp, + 'specification' => $userCard->specification, + '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; diff --git a/common/services/UserCardService.php b/common/services/UserCardService.php deleted file mode 100644 index bb743c2..0000000 --- a/common/services/UserCardService.php +++ /dev/null @@ -1,27 +0,0 @@ - $user_id]); - if (empty($userCard)) { - throw new ServerErrorHttpException(json_encode($userCard->errors)); - } - return array('fio' => $userCard->fio, - 'photo' => $userCard->photo, - 'gender' => $userCard->gender, - 'level' => $userCard->level, - 'years_of_exp' => $userCard->years_of_exp, - 'specification' => $userCard->specification, - 'position_name' => $userCard->position->name); - } -} \ No newline at end of file diff --git a/docs/api/profile.md b/docs/api/profile.md index 3c69b84..f795fa9 100644 --- a/docs/api/profile.md +++ b/docs/api/profile.md @@ -1,4 +1,4 @@ -## Профиль +# Профиль ## Методы @@ -33,6 +33,14 @@ Получить профиль с флагом прав на просмотр отчётов этого пользователя + + + +
+ profile/get-main-data + + Получить получить основные данные профиля +
### Список @@ -194,3 +202,107 @@ +## Основные данные пользователя + +`https://guild.craft-group.xyz/api/profile/get-main-data?user_id=1` +

+ Требуемые параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ user_id + + Id профиля пользователя +
+ +

+ Возвращает объект Пользователь.
+ Каждый объект Пользователь имеет такой вид: +

+ +```json5 +{ + "fio": "Тест менеджер для апи запроса", + "photo": null, + "gender": 1, + "level": 2, + "years_of_exp": null, + "specification": null, + "position_name": "Должность 1" +} +``` + +

+ Возвращаемые параметры: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ fio + + ФИО +
+ photo + + Ссылка на фото +
+ gender + + Пол +
+ level + + Уровень +
+ years_of_exp + + Лет опыта +
+ position_name + + Должность +
+ diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 1269486..70c3a7c 100755 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -4,6 +4,7 @@ namespace frontend\modules\api\controllers; use common\services\ProfileService; use yii\web\BadRequestHttpException; +use yii\web\ServerErrorHttpException; class ProfileController extends ApiController { @@ -15,7 +16,7 @@ class ProfileController extends ApiController ]; } - public function actionIndex($id = null) + public function actionIndex($id = null): ?array { return ProfileService::getProfile($id, \Yii::$app->request->get()); } @@ -27,4 +28,12 @@ class ProfileController extends ApiController { return ProfileService::getProfileWithReportPermission($id); } + + /** + * @throws ServerErrorHttpException + */ + public function actionGetMainData($user_id): array + { + return ProfileService::getMainData($user_id); + } } \ No newline at end of file diff --git a/frontend/modules/api/controllers/UserCardController.php b/frontend/modules/api/controllers/UserCardController.php deleted file mode 100644 index bdbebdd..0000000 --- a/frontend/modules/api/controllers/UserCardController.php +++ /dev/null @@ -1,24 +0,0 @@ - ['get'], - ]; - } - - /** - * @throws ServerErrorHttpException - */ - public function actionGetUserCard($user_id): array - { - return UserCardService::getUserCard($user_id); - } -} \ No newline at end of file