the method was moved UserCard to Profile
This commit is contained in:
parent
d11deb20af
commit
16db7b42d9
@ -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;
|
||||
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\models\UserCard;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class UserCardService
|
||||
{
|
||||
/**
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public static function getUserCard($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);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
## Профиль
|
||||
# Профиль
|
||||
## Методы
|
||||
<table>
|
||||
<tr>
|
||||
@ -33,6 +33,14 @@
|
||||
Получить профиль с флагом прав на просмотр отчётов этого пользователя
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
profile/get-main-data
|
||||
</td>
|
||||
<td>
|
||||
Получить получить основные данные профиля
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Список
|
||||
@ -194,3 +202,107 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Основные данные пользователя
|
||||
|
||||
`https://guild.craft-group.xyz/api/profile/get-main-data?user_id=1`
|
||||
<p>
|
||||
Требуемые параметры:
|
||||
</p>
|
||||
<table>
|
||||
<tr>
|
||||
<th>
|
||||
Параметры
|
||||
</th>
|
||||
<th>
|
||||
Значение
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
user_id
|
||||
</td>
|
||||
<td>
|
||||
Id профиля пользователя
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
Возвращает объект <b>Пользователь</b>. <br>
|
||||
Каждый объект <b>Пользователь</b> имеет такой вид:
|
||||
</p>
|
||||
|
||||
```json5
|
||||
{
|
||||
"fio": "Тест менеджер для апи запроса",
|
||||
"photo": null,
|
||||
"gender": 1,
|
||||
"level": 2,
|
||||
"years_of_exp": null,
|
||||
"specification": null,
|
||||
"position_name": "Должность 1"
|
||||
}
|
||||
```
|
||||
|
||||
<p>
|
||||
Возвращаемые параметры:
|
||||
</p>
|
||||
<table>
|
||||
<tr>
|
||||
<th>
|
||||
Параметры
|
||||
</th>
|
||||
<th>
|
||||
Значение
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
fio
|
||||
</td>
|
||||
<td>
|
||||
ФИО
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
photo
|
||||
</td>
|
||||
<td>
|
||||
Ссылка на фото
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
gender
|
||||
</td>
|
||||
<td>
|
||||
Пол
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
level
|
||||
</td>
|
||||
<td>
|
||||
Уровень
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
years_of_exp
|
||||
</td>
|
||||
<td>
|
||||
Лет опыта
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
position_name
|
||||
</td>
|
||||
<td>
|
||||
Должность
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\services\UserCardService;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class UserCardController extends ApiController
|
||||
{
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
'get-user-card' => ['get'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function actionGetUserCard($user_id): array
|
||||
{
|
||||
return UserCardService::getUserCard($user_id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user