project Employees

This commit is contained in:
Kavalar 2023-05-04 01:18:24 +03:00
parent 1b8ca5b695
commit b2f482e10b
4 changed files with 142 additions and 12 deletions

View File

@ -50,6 +50,21 @@ class ManagerEmployee extends \yii\db\ActiveRecord
]; ];
} }
public function fields(): array
{
return [
'id',
'manager_id',
'employee_id',
'employee' => function () {
return [
"fio" => $this->employee->userCard->fio ?? $this->employee->username,
"avatar" => $this->employee->userCard->photo ?? '',
];
},
];
}
/** /**
* @return ActiveQuery * @return ActiveQuery
*/ */

View File

@ -7,6 +7,7 @@ use common\models\ProjectTaskCategory;
use common\models\ProjectUser; use common\models\ProjectUser;
use common\models\Status; use common\models\Status;
use common\models\UseStatus; use common\models\UseStatus;
use frontend\modules\api\models\Manager;
use frontend\modules\api\models\Project; use frontend\modules\api\models\Project;
use Yii; use Yii;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
@ -134,12 +135,12 @@ class ProjectController extends ApiController
*/ */
public function actionProjectList($user_id = null): ActiveDataProvider public function actionProjectList($user_id = null): ActiveDataProvider
{ {
if (!$user_id){ if (!$user_id) {
$user_id = Yii::$app->user->id; $user_id = Yii::$app->user->id;
} }
if (!empty($user_id)) { if (!empty($user_id)) {
$projectIdList = ProjectUser::find()->where(['user_id' => $user_id])->select('project_id')->column(); $projectIdList = ProjectUser::find()->where(['user_id' => $user_id])->select('project_id')->column();
$query = Project::find()->where([ 'IN', 'id', $projectIdList])->andWhere(['status' => Project::STATUS_OTHER])->orWhere(['owner_id' => $user_id]); $query = Project::find()->where(['IN', 'id', $projectIdList])->andWhere(['status' => Project::STATUS_OTHER])->orWhere(['owner_id' => $user_id]);
} else { } else {
$query = Project::find(); $query = Project::find();
} }
@ -166,7 +167,7 @@ class ProjectController extends ApiController
$projectTaskCategory = new ProjectTaskCategory(); $projectTaskCategory = new ProjectTaskCategory();
$projectTaskCategory->attributes = \yii::$app->request->post(); $projectTaskCategory->attributes = \yii::$app->request->post();
if($projectTaskCategory->validate()) { if ($projectTaskCategory->validate()) {
$projectTaskCategory->save(false); $projectTaskCategory->save(false);
return $projectTaskCategory; return $projectTaskCategory;
} }
@ -180,7 +181,7 @@ class ProjectController extends ApiController
->andWhere(['title' => Yii::$app->request->post('title')]) ->andWhere(['title' => Yii::$app->request->post('title')])
->one(); ->one();
if(empty($projectTaskCategory)) { if (empty($projectTaskCategory)) {
throw new NotFoundHttpException('The project not found'); throw new NotFoundHttpException('The project not found');
} }
@ -255,7 +256,7 @@ class ProjectController extends ApiController
$project->load(\yii::$app->request->post(), ''); $project->load(\yii::$app->request->post(), '');
$project->owner_id = $user_id; $project->owner_id = $user_id;
if($project->validate()) { if ($project->validate()) {
$project->save(false); $project->save(false);
return $project; return $project;
} }
@ -326,11 +327,11 @@ class ProjectController extends ApiController
public function actionUpdate() public function actionUpdate()
{ {
$request = Yii::$app->request->getBodyParams(); $request = Yii::$app->request->getBodyParams();
if (!isset($request['project_id']) || $request['project_id'] == null){ if (!isset($request['project_id']) || $request['project_id'] == null) {
throw new BadRequestHttpException(json_encode(['The project ID not found'])); throw new BadRequestHttpException(json_encode(['The project ID not found']));
} }
$project = Project::findOne($request['project_id']); $project = Project::findOne($request['project_id']);
if(empty($project)) { if (empty($project)) {
throw new NotFoundHttpException('The project not found'); throw new NotFoundHttpException('The project not found');
} }
@ -341,4 +342,43 @@ class ProjectController extends ApiController
} }
return $project; return $project;
} }
/**
*
* @OA\Get(path="/project/my-employee",
* summary="Список Сотрудников текущего пользователя",
* description="Метод для получения списка сотрудников",
* security={
* {"bearerAuth": {}}
* },
* tags={"TaskManager"},
*
* @OA\Response(
* response=200,
* description="Возвращает объект Менеджера",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ManagerEmployee"),
* ),
* ),
* )
*
* @return array|\yii\db\ActiveRecord
* @throws BadRequestHttpException
*/
public function actionMyEmployee()
{
$user_id = \Yii::$app->user->id;
if (!$user_id) {
throw new BadRequestHttpException(json_encode(['Пользователь не найден']));
}
$model = Manager::find()->with(['managerEmployees'])->where(['user_id' => $user_id])->one();
if (!$model){
throw new BadRequestHttpException(json_encode(['Менеджер не найден']));
}
return $model;
}
} }

View File

@ -0,0 +1,16 @@
<?php
namespace frontend\modules\api\models;
class Manager extends \common\models\Manager
{
public function fields(): array
{
return [
'id',
'user_id',
'managerEmployees'
];
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace frontend\modules\api\models;
/**
*
* @OA\Schema(
* schema="ManagerEmployee",
* @OA\Property(
* property="id",
* type="int",
* example=95,
* description="Идентификатор задачи"
* ),
* @OA\Property(
* property="user_id",
* type="int",
* example="19",
* description="Идентификатор пользователя"
* ),
* @OA\Property(
* property="managerEmployees",
* ref="#/components/schemas/ManagerEmployees",
* ),
*)
*
* @OA\Schema(
* schema="ManagerEmployees",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="id",
* type="integer",
* example="1"
* ),
* @OA\Property(
* property="manager_id",
* type="integer",
* example="1"
* ),
* @OA\Property(
* property="employee_id",
* type="integer",
* example="19"
* ),
* @OA\Property(
* property="employee",
* type="object",
* ref="#/components/schemas/ProjectTaskUsersShortExample",
* ),
* ),
*)
*
*/
class ManagerEmployee extends \common\models\ManagerEmployee
{
}