edit request, skills list, position list
This commit is contained in:
parent
8bc601aa6a
commit
7f46dc1346
@ -4,6 +4,7 @@ namespace common\services;
|
|||||||
|
|
||||||
use common\models\Manager;
|
use common\models\Manager;
|
||||||
use common\models\ManagerEmployee;
|
use common\models\ManagerEmployee;
|
||||||
|
use common\models\Position;
|
||||||
use common\models\UserCard;
|
use common\models\UserCard;
|
||||||
use common\models\UserCardPortfolioProjects;
|
use common\models\UserCardPortfolioProjects;
|
||||||
use frontend\modules\api\models\ProfileSearchForm;
|
use frontend\modules\api\models\ProfileSearchForm;
|
||||||
@ -84,6 +85,14 @@ class ProfileService
|
|||||||
throw new ServerErrorHttpException('There is no user with this id');
|
throw new ServerErrorHttpException('There is no user with this id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|\yii\db\ActiveRecord[]
|
||||||
|
*/
|
||||||
|
public static function getPositionsList()
|
||||||
|
{
|
||||||
|
return Position::find()->all();
|
||||||
|
}
|
||||||
|
|
||||||
private static function addPermission(&$profile, $user_card_id)
|
private static function addPermission(&$profile, $user_card_id)
|
||||||
{
|
{
|
||||||
$searcherCardID = self::getSearcherCardID(Yii::$app->user->getId());
|
$searcherCardID = self::getSearcherCardID(Yii::$app->user->getId());
|
||||||
|
@ -146,7 +146,7 @@ class RequestService
|
|||||||
*/
|
*/
|
||||||
public function getByUserId($user_id)
|
public function getByUserId($user_id)
|
||||||
{
|
{
|
||||||
return $this->model->find()->where(['user_id' => $user_id])->all();
|
return $this->model->find()->where(['user_id' => $user_id, 'status' => 1])->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,6 +160,19 @@ class RequestService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $userId
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateUser(int $userId): bool
|
||||||
|
{
|
||||||
|
if ($this->model->user_id == $userId){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|int
|
* @return array|int
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,8 @@ class ProfileController extends ApiController
|
|||||||
'actions' => [
|
'actions' => [
|
||||||
'' => ['GET', 'HEAD', 'OPTIONS'],
|
'' => ['GET', 'HEAD', 'OPTIONS'],
|
||||||
'profile-with-report-permission' => ['post', 'patch'],
|
'profile-with-report-permission' => ['post', 'patch'],
|
||||||
'get-main-data' => ['get']
|
'get-main-data' => ['get'],
|
||||||
|
'positions-list' => ['get'],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
@ -31,7 +32,7 @@ class ProfileController extends ApiController
|
|||||||
*/
|
*/
|
||||||
public function actionIndex($id = null): ?array
|
public function actionIndex($id = null): ?array
|
||||||
{
|
{
|
||||||
return ProfileService::getProfile($id, \Yii::$app->request->get());
|
return ProfileService::getProfile($id, \Yii::$app->request->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,4 +55,31 @@ class ProfileController extends ApiController
|
|||||||
{
|
{
|
||||||
return ProfileService::getPortfolioProjects($card_id);
|
return ProfileService::getPortfolioProjects($card_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @OA\Get(path="/profile/positions-list",
|
||||||
|
* summary="Список позиций",
|
||||||
|
* description="Получить список всех возможных позиций",
|
||||||
|
* tags={"Profile"},
|
||||||
|
* security={
|
||||||
|
* {"bearerAuth": {}}
|
||||||
|
* },
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Возвращает массив позиций",
|
||||||
|
* @OA\MediaType(
|
||||||
|
* mediaType="application/json",
|
||||||
|
* @OA\Schema(ref="#/components/schemas/PositionsExample"),
|
||||||
|
* ),
|
||||||
|
*
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function actionPositionsList(): array
|
||||||
|
{
|
||||||
|
return ProfileService::getPositionsList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ namespace frontend\modules\api\controllers;
|
|||||||
use common\classes\Debug;
|
use common\classes\Debug;
|
||||||
use common\models\Request;
|
use common\models\Request;
|
||||||
use common\services\RequestService;
|
use common\services\RequestService;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
use yii\web\BadRequestHttpException;
|
use yii\web\BadRequestHttpException;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class RequestController extends ApiController
|
|||||||
'get-request' => ['get'],
|
'get-request' => ['get'],
|
||||||
'get-request-list' => ['get'],
|
'get-request-list' => ['get'],
|
||||||
'create-request' => ['post'],
|
'create-request' => ['post'],
|
||||||
// 'update-task' => ['put', 'patch'],
|
'update-request' => ['put', 'patch'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ class RequestController extends ApiController
|
|||||||
* @param int|null $user_id
|
* @param int|null $user_id
|
||||||
* @return array|\yii\db\ActiveRecord[]
|
* @return array|\yii\db\ActiveRecord[]
|
||||||
*/
|
*/
|
||||||
public function actionGetList(int $user_id = null, int $search_depth = 3): array
|
public function actionGetRequestList(int $user_id = null, int $search_depth = 3): array
|
||||||
{
|
{
|
||||||
if (!$user_id) {
|
if (!$user_id) {
|
||||||
$user_id = \Yii::$app->user->id;
|
$user_id = \Yii::$app->user->id;
|
||||||
@ -133,8 +134,8 @@ class RequestController extends ApiController
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @OA\Post(path="/request/create-request",
|
* @OA\Post(path="/request/create-request",
|
||||||
* summary="Получить список запросов",
|
* summary="Добавить запрос",
|
||||||
* description="Метод для оздания запроса, если не передан параметр <b>user_id</b>, то будет получен список текущего пользователя",
|
* description="Метод для создания запроса, если не передан параметр <b>user_id</b>, то будет получен список текущего пользователя",
|
||||||
* security={
|
* security={
|
||||||
* {"bearerAuth": {}}
|
* {"bearerAuth": {}}
|
||||||
* },
|
* },
|
||||||
@ -177,7 +178,7 @@ class RequestController extends ApiController
|
|||||||
* ),
|
* ),
|
||||||
* @OA\Property(
|
* @OA\Property(
|
||||||
* property="descr",
|
* property="descr",
|
||||||
* type=" string",
|
* type="string",
|
||||||
* description="Описание запроса",
|
* description="Описание запроса",
|
||||||
* ),
|
* ),
|
||||||
* @OA\Property(
|
* @OA\Property(
|
||||||
@ -204,10 +205,10 @@ class RequestController extends ApiController
|
|||||||
* @return Request
|
* @return Request
|
||||||
* @throws BadRequestHttpException
|
* @throws BadRequestHttpException
|
||||||
*/
|
*/
|
||||||
public function actionCreateRequest()
|
public function actionCreateRequest(): Request
|
||||||
{
|
{
|
||||||
$user_id = \Yii::$app->user->id;
|
$user_id = \Yii::$app->user->id;
|
||||||
if (!$user_id){
|
if (!$user_id) {
|
||||||
throw new BadRequestHttpException(json_encode(['Пользователь не найден']));
|
throw new BadRequestHttpException(json_encode(['Пользователь не найден']));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +217,118 @@ class RequestController extends ApiController
|
|||||||
->load(\Yii::$app->request->post(), '')
|
->load(\Yii::$app->request->post(), '')
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
if (!$requestService->isSave){
|
if (!$requestService->isSave) {
|
||||||
|
throw new BadRequestHttpException(json_encode($requestService->errors));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $requestService->getModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @OA\Put(path="/request/update-request",
|
||||||
|
* summary="Редактировать запрос",
|
||||||
|
* description="Метод для редактирования запроса, если не передан параметр <b>user_id</b>, то будет получен список текущего пользователя",
|
||||||
|
* security={
|
||||||
|
* {"bearerAuth": {}}
|
||||||
|
* },
|
||||||
|
* tags={"Requests"},
|
||||||
|
*
|
||||||
|
* @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="request_id",
|
||||||
|
* type="integer",
|
||||||
|
* description="Идентификатор запросв",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="title",
|
||||||
|
* type="string",
|
||||||
|
* description="Заголовок запроса",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="position_id",
|
||||||
|
* type="integer",
|
||||||
|
* description="Позиция",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="knowledge_level_id",
|
||||||
|
* type="integer",
|
||||||
|
* description="Уровень",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="specialist_count",
|
||||||
|
* type="integer",
|
||||||
|
* description="Количество специалистов",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="status",
|
||||||
|
* type="integer",
|
||||||
|
* description="Статус запроса",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="descr",
|
||||||
|
* type="string",
|
||||||
|
* description="Описание запроса",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="skill_ids",
|
||||||
|
* type="array",
|
||||||
|
* description="Навыки",
|
||||||
|
* @OA\Items(
|
||||||
|
* type="integer",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Возвращает объект Запроса",
|
||||||
|
* @OA\MediaType(
|
||||||
|
* mediaType="application/json",
|
||||||
|
* @OA\Schema(ref="#/components/schemas/Request"),
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return Request|null
|
||||||
|
* @throws BadRequestHttpException
|
||||||
|
* @throws InvalidConfigException
|
||||||
|
*/
|
||||||
|
public function actionUpdateRequest(): Request
|
||||||
|
{
|
||||||
|
$user_id = \Yii::$app->user->id;
|
||||||
|
if (!$user_id) {
|
||||||
|
throw new BadRequestHttpException(json_encode(['User not found']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$request_id = \Yii::$app->request->getBodyParam('request_id');
|
||||||
|
if (!$request_id) {
|
||||||
|
throw new BadRequestHttpException(json_encode(['Request not found']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestService = RequestService::run($request_id);
|
||||||
|
|
||||||
|
if (!$requestService->validateUser($user_id)){
|
||||||
|
throw new BadRequestHttpException(json_encode(['The user does not have the right to edit the request'], true));
|
||||||
|
}
|
||||||
|
|
||||||
|
$put = array_diff(\Yii::$app->request->getBodyParams(), [null, '']);
|
||||||
|
|
||||||
|
$requestService->load($put, '')
|
||||||
|
->save();
|
||||||
|
|
||||||
|
if (!$requestService->isSave) {
|
||||||
throw new BadRequestHttpException(json_encode($requestService->errors));
|
throw new BadRequestHttpException(json_encode($requestService->errors));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ namespace frontend\modules\api\controllers;
|
|||||||
|
|
||||||
use common\behaviors\GsCors;
|
use common\behaviors\GsCors;
|
||||||
use common\models\Options;
|
use common\models\Options;
|
||||||
|
use common\models\Skill;
|
||||||
use yii\filters\AccessControl;
|
use yii\filters\AccessControl;
|
||||||
use yii\filters\auth\CompositeAuth;
|
use yii\filters\auth\CompositeAuth;
|
||||||
use yii\filters\auth\HttpBearerAuth;
|
use yii\filters\auth\HttpBearerAuth;
|
||||||
@ -34,11 +35,40 @@ class SkillsController extends ApiController
|
|||||||
return array_merge($parent, $b);
|
return array_merge($parent, $b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function verbs(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'skills-on-main-page' => ['get'],
|
||||||
|
'get-skills-list' => ['get'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
{
|
{
|
||||||
return ['some' => 'rrr'];
|
return ['some' => 'rrr'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @OA\Get(path="/skills/skills-on-main-page",
|
||||||
|
* summary="Получить список навыков для отображения на главной",
|
||||||
|
* description="Получить список навыков на главной странице",
|
||||||
|
* tags={"Skills"},
|
||||||
|
* security={
|
||||||
|
* {"bearerAuth": {}}
|
||||||
|
* },
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Возвращает массив навыков",
|
||||||
|
* @OA\MediaType(
|
||||||
|
* mediaType="application/json",
|
||||||
|
* ),
|
||||||
|
*
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return array|mixed
|
||||||
|
*/
|
||||||
public function actionSkillsOnMainPage()
|
public function actionSkillsOnMainPage()
|
||||||
{
|
{
|
||||||
$data = \common\models\Options::getValue('skills_on_main_page_to_front');
|
$data = \common\models\Options::getValue('skills_on_main_page_to_front');
|
||||||
@ -48,4 +78,31 @@ class SkillsController extends ApiController
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @OA\Get(path="/skills/get-skills-list",
|
||||||
|
* summary="Получить список навыков",
|
||||||
|
* description="Получить список навыков",
|
||||||
|
* tags={"Skills"},
|
||||||
|
* security={
|
||||||
|
* {"bearerAuth": {}}
|
||||||
|
* },
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Возвращает массив навыков",
|
||||||
|
* @OA\MediaType(
|
||||||
|
* mediaType="application/json",
|
||||||
|
* @OA\Schema(ref="#/components/schemas/SkillsExample"),
|
||||||
|
* ),
|
||||||
|
*
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return array|\yii\db\ActiveRecord[]
|
||||||
|
*/
|
||||||
|
public function actionGetSkillsList(): array
|
||||||
|
{
|
||||||
|
return Skill::find()->all();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,23 @@ namespace frontend\modules\api\models;
|
|||||||
* description="Название позиции"
|
* description="Название позиции"
|
||||||
* ),
|
* ),
|
||||||
*)
|
*)
|
||||||
|
*
|
||||||
|
* @OA\Schema(
|
||||||
|
* schema="PositionsExample",
|
||||||
|
* type="array",
|
||||||
|
* example={{"id": 1, "name": "Back end - разработчик"}, {"id": 2, "name": "Front end - разработчик"}},
|
||||||
|
* @OA\Items(
|
||||||
|
* type="object",
|
||||||
|
* @OA\Property(
|
||||||
|
* property="id",
|
||||||
|
* type="integer",
|
||||||
|
* ),
|
||||||
|
* @OA\Property(
|
||||||
|
* property="name",
|
||||||
|
* type="string",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
*)
|
||||||
*/
|
*/
|
||||||
class Position extends \common\models\Position
|
class Position extends \common\models\Position
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user