diff --git a/backend/modules/task/models/TaskSearch.php b/backend/modules/task/models/TaskSearch.php
index 3e76ba9..54513c7 100644
--- a/backend/modules/task/models/TaskSearch.php
+++ b/backend/modules/task/models/TaskSearch.php
@@ -18,7 +18,7 @@ class TaskSearch extends ProjectTask
public function rules()
{
return [
- [['id', 'project_id', 'status', 'card_id_creator', 'card_id'], 'integer'], // 'card_id_creator', 'card_id'
+ [['id', 'project_id', 'status'], 'integer'], // 'card_id_creator', 'card_id'
[['title', 'created_at', 'updated_at', 'description'], 'safe'],
];
}
@@ -64,8 +64,6 @@ class TaskSearch extends ProjectTask
'task.status' => $this->status,
'task.created_at' => $this->created_at,
'task.updated_at' => $this->updated_at,
- 'task.card_id_creator' => $this->card_id_creator,
- 'task.card_id' => $this->card_id,
]);
$query->andFilterWhere(['like', 'title', $this->title])
diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php
index 8c47482..a71fc3c 100644
--- a/backend/modules/task/views/task/_form.php
+++ b/backend/modules/task/views/task/_form.php
@@ -24,13 +24,13 @@ use yii\widgets\ActiveForm;
);
?>
- = $form->field($model, 'card_id_creator')->widget(Select2::class,
+ = $form->field($model, 'user_id')->widget(
+ Select2::class,
[
- 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
- 'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
+ 'data' => \common\models\UserCard::getListUserWithUserId(),
+ 'options' => ['placeholder' => '...', 'class' => 'form-control'],
'pluginOptions' => [
- 'allowClear' => true,
- 'prompt' => 'Выберите'
+ 'allowClear' => true
],
]
); ?>
@@ -44,9 +44,9 @@ use yii\widgets\ActiveForm;
]
) ?>
- = $form->field($model, 'card_id')->widget(Select2::class,
+ = $form->field($model, 'column_id')->widget(Select2::class,
[
- 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
+ 'data' => \common\models\ProjectColumn::find()->select(['title', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true,
diff --git a/backend/modules/task/views/task/index.php b/backend/modules/task/views/task/index.php
index 812c9a5..7978a72 100644
--- a/backend/modules/task/views/task/index.php
+++ b/backend/modules/task/views/task/index.php
@@ -49,42 +49,6 @@ $this->params['breadcrumbs'][] = $this->title;
])
],
'title',
- [
- 'attribute' => 'card_id_creator',
- 'value' => 'userCardCreator.fio',
- 'filter' => Select2::widget([
- 'model' => $searchModel,
- 'attribute' => 'card_id_creator',
- 'data' => ProjectTask::find()->joinWith('userCardCreator')
- ->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
- 'pluginOptions' => [
- 'allowClear' => true,
- 'width' => '150px',
- ],
- 'options' => [
- 'class' => 'form-control',
- 'placeholder' => 'Выберите значение'
- ],
- ])
- ],
- [
- 'attribute' => 'card_id',
- 'value' => 'userCard.fio',
- 'filter' => Select2::widget([
- 'model' => $searchModel,
- 'attribute' => 'card_id',
- 'data' => ProjectTask::find()->joinWith('userCard')
- ->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
- 'pluginOptions' => [
- 'allowClear' => true,
- 'width' => '150px',
- ],
- 'options' => [
- 'class' => 'form-control',
- 'placeholder' => 'Выберите значение'
- ],
- ])
- ],
'description',
[
'attribute' => 'status',
diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php
index 61c6da6..71b8268 100644
--- a/backend/modules/task/views/task/view.php
+++ b/backend/modules/task/views/task/view.php
@@ -47,12 +47,12 @@ YiiAsset::register($this);
'created_at',
'updated_at',
[
- 'attribute' => 'card_id_creator',
- 'value' => ArrayHelper::getValue($model, 'userCardCreator.fio'),
+ 'attribute' => 'column_id',
+ 'value' => ArrayHelper::getValue($model, 'column.title'),
],
[
- 'attribute' => 'card_id',
- 'value' => ArrayHelper::getValue($model, 'userCard.fio'),
+ 'attribute' => 'user_id',
+ 'value' => ArrayHelper::getValue($model, 'user.userCard.fio'),
],
'description',
],
diff --git a/common/models/Project.php b/common/models/Project.php
index 5eaf2b4..dced535 100755
--- a/common/models/Project.php
+++ b/common/models/Project.php
@@ -101,6 +101,14 @@ class Project extends \yii\db\ActiveRecord
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getColumns()
+ {
+ return $this->hasMany(ProjectColumn::class, ['project_id' => 'id'])->with('tasks');
+ }
+
/**
* @return \yii\db\ActiveQuery
*/
diff --git a/common/models/ProjectColumn.php b/common/models/ProjectColumn.php
index 10d4dba..167884d 100644
--- a/common/models/ProjectColumn.php
+++ b/common/models/ProjectColumn.php
@@ -22,6 +22,7 @@ class ProjectColumn extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0;
+
/**
* {@inheritdoc}
*/
@@ -30,6 +31,30 @@ class ProjectColumn extends \yii\db\ActiveRecord
return 'project_column';
}
+ /**
+ * @return string[]
+ */
+ public function fields(): array
+ {
+ return [
+ 'id',
+ 'title',
+ 'created_at',
+ 'updated_at',
+ 'project_id',
+ 'status',
+ 'tasks',
+ ];
+ }
+
+ /**
+ * @return string[]
+ */
+ public function extraFields(): array
+ {
+ return [];
+ }
+
/**
* {@inheritdoc}
*/
@@ -92,4 +117,12 @@ class ProjectColumn extends \yii\db\ActiveRecord
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getTasks()
+ {
+ return $this->hasMany(ProjectTask::class, ['column_id' => 'id'])->with('taskUsers');
+ }
}
diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php
index 249cf12..4cb140a 100644
--- a/common/models/ProjectTask.php
+++ b/common/models/ProjectTask.php
@@ -17,8 +17,8 @@ use yii\helpers\ArrayHelper;
* @property int $status
* @property string $created_at
* @property string $updated_at
- * @property int $card_id_creator
- * @property int $card_id
+ * @property int $column_id
+ * @property int $user_id
* @property string $description
*
* @property Project $project
@@ -54,15 +54,15 @@ class ProjectTask extends ActiveRecord
public function rules()
{
return [
- [['project_id', 'status', 'title', 'description', 'card_id_creator',], 'required'],
- [['project_id', 'status', 'card_id_creator', 'card_id'], 'integer'],
+ [['project_id', 'status', 'title', 'description',], 'required'],
+ [['project_id', 'status', 'column_id', 'user_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
- ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message'=>'Такая задача уже создана'],
+ ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'],
[['title'], 'string', 'max' => 255],
[['description'], 'string', 'max' => 500],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
- [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
- [['card_id_creator'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id_creator' => 'id']],
+ [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
+ [['column_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectColumn::className(), 'targetAttribute' => ['column_id' => 'id']],
];
}
@@ -79,14 +79,33 @@ class ProjectTask extends ActiveRecord
'created_at' => 'Дата создания',
'updated_at' => 'Дата обновления',
'description' => 'Описание',
- 'card_id_creator' => 'Создатель задачи',
- 'card_id' => 'Наблюдатель',
+ 'user_id' => 'Создатель задачи',
+ 'column_id' => 'Колонка',
+ ];
+ }
+
+ /**
+ * @return string[]
+ */
+ public function fields(): array
+ {
+ return [
+ 'id',
+ 'project_id',
+ 'title',
+ 'created_at',
+ 'updated_at',
+ 'description',
+ 'status',
+ 'column_id',
+ 'user_id',
+ 'taskUsers',
];
}
public function beforeDelete()
{
- foreach ($this->taskUsers as $taskUser){
+ foreach ($this->taskUsers as $taskUser) {
$taskUser->delete();
}
return parent::beforeDelete();
@@ -108,14 +127,12 @@ class ProjectTask extends ActiveRecord
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
- public function getUserCard()
+ /**
+ * @return ActiveQuery
+ */
+ public function getColumn(): ActiveQuery
{
- return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
- }
-
- public function getUserCardCreator()
- {
- return $this->hasOne(UserCard::className(), ['id' => 'card_id_creator']);
+ return $this->hasOne(ProjectColumn::class, ['id' => 'column_id']);
}
/**
diff --git a/common/models/ProjectTaskUser.php b/common/models/ProjectTaskUser.php
index 30cb621..fb22cec 100644
--- a/common/models/ProjectTaskUser.php
+++ b/common/models/ProjectTaskUser.php
@@ -9,7 +9,7 @@ use yii\db\ActiveQuery;
*
* @property int $id
* @property int $task_id
- * @property int $project_user_id
+ * @property int $user_id
*
* @property ProjectUser $projectUser
* @property ProjectTask $task
@@ -30,13 +30,31 @@ class ProjectTaskUser extends \yii\db\ActiveRecord
public function rules()
{
return [
- [['task_id', 'project_user_id'], 'required'],
- ['project_user_id', 'unique', 'targetAttribute' => ['task_id', 'project_user_id'], 'message'=>'Уже закреплён(ы) за задачей'],
- [['project_user_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectUser::className(), 'targetAttribute' => ['project_user_id' => 'id']],
+ [['task_id', 'user_id'], 'required'],
+ ['user_id', 'unique', 'targetAttribute' => ['task_id', 'user_id'], 'message' => 'Уже закреплён(ы) за задачей'],
+ [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectTask::className(), 'targetAttribute' => ['task_id' => 'id']],
];
}
+ /**
+ * @return string[]
+ */
+ public function fields(): array
+ {
+ return [
+ 'id',
+ 'task_id',
+ 'user_id',
+ 'fio' => function () {
+ return $this->user->userCard->fio ?? $this->user->username;
+ },
+ 'avatar' => function () {
+ return $this->user->userCard->photo ?? '';
+ }
+ ];
+ }
+
/**
* {@inheritdoc}
*/
@@ -45,16 +63,13 @@ class ProjectTaskUser extends \yii\db\ActiveRecord
return [
'id' => 'ID',
'task_id' => 'Задача',
- 'project_user_id' => 'Сотрудник',
+ 'user_id' => 'Сотрудник',
];
}
- /**
- * @return ActiveQuery
- */
- public function getProjectUser()
+ public function getUser()
{
- return $this->hasOne(ProjectUser::className(), ['id' => 'project_user_id']);
+ return $this->hasOne(User::class, ['id' => 'user_id']);
}
/**
diff --git a/common/services/TaskService.php b/common/services/TaskService.php
index bbe373e..2086697 100644
--- a/common/services/TaskService.php
+++ b/common/services/TaskService.php
@@ -29,6 +29,11 @@ class TaskService
return ProjectTask::find()->where(['project_id' => $project_id])->asArray()->all();
}
+ public static function getTaskListByUser($user_id): array
+ {
+ return ProjectTask::find()->where(['user_id' => $user_id])->all();
+ }
+
public static function updateTask($task_params): ?ProjectTask
{
$modelTask = ProjectTask::findOne($task_params['task_id']);
diff --git a/console/migrations/m230420_211818_change_user_card_to_user_at_project_task_table.php b/console/migrations/m230420_211818_change_user_card_to_user_at_project_task_table.php
new file mode 100644
index 0000000..d8ce4ea
--- /dev/null
+++ b/console/migrations/m230420_211818_change_user_card_to_user_at_project_task_table.php
@@ -0,0 +1,56 @@
+dropForeignKey('task_user_card_creator', 'project_task');
+ $this->dropForeignKey('task_user_card', 'project_task');
+ $this->dropColumn('project_task', 'card_id_creator');
+ $this->dropColumn('project_task', 'card_id');
+
+ $this->addColumn('project_task', 'column_id', $this->integer());
+ $this->addColumn('project_task', 'user_id', $this->integer());
+ $this->addForeignKey('fk_project_task_column', 'project_task', 'column_id', 'project_column', 'id');
+ $this->addForeignKey('fk_project_task_user', 'project_task', 'user_id', 'user', 'id');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('fk_project_task_column', 'project_task');
+ $this->dropForeignKey('fk_project_task_user', 'project_task');
+ $this->dropColumn('project_task', 'column_id');
+ $this->dropColumn('project_task', 'user_id');
+
+ $this->addColumn('project_task', 'card_id_creator', $this->integer());
+ $this->addColumn('project_task', 'card_id', $this->integer());
+ $this->addForeignKey('task_user_card_creator', 'project_task', 'card_id_creator', 'user_card', 'id');
+ $this->addForeignKey('task_user_card', 'project_task', 'card_id', 'user_card', 'id');
+ }
+
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m230420_211818_change_user_card_to_user_at_project_task_table cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}
diff --git a/console/migrations/m230420_221309_change_column_project_user_id_to_user_id_at_project_task_user_table.php b/console/migrations/m230420_221309_change_column_project_user_id_to_user_id_at_project_task_user_table.php
new file mode 100644
index 0000000..b07604b
--- /dev/null
+++ b/console/migrations/m230420_221309_change_column_project_user_id_to_user_id_at_project_task_user_table.php
@@ -0,0 +1,48 @@
+dropForeignKey('project_user_task_user', 'project_task_user');
+ $this->dropColumn('project_task_user', 'project_user_id');
+
+ $this->addColumn('project_task_user', 'user_id', $this->integer());
+ $this->addForeignKey('fk_project_task_user_user', 'project_task_user', 'user_id', 'user', 'id');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('fk_project_task_user_user', 'project_task_user');
+ $this->dropColumn('project_task_user', 'user_id');
+
+ $this->addColumn('project_task_user', 'project_user_id', $this->integer());
+ $this->addForeignKey('project_user_task_user', 'project_task_user', 'project_user_id', 'project_user', 'id');
+ }
+
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m230420_221309_change_column_project_user_id_to_user_id_at_project_task_user_table cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}
diff --git a/frontend/modules/api/controllers/ProjectColumnController.php b/frontend/modules/api/controllers/ProjectColumnController.php
new file mode 100644
index 0000000..de61792
--- /dev/null
+++ b/frontend/modules/api/controllers/ProjectColumnController.php
@@ -0,0 +1,129 @@
+ ['get'],
+ 'get-column-list' => ['get'],
+ 'create-column' => ['post'],
+ 'update-column' => ['put', 'patch'],
+ ];
+ }
+
+ public function actionGetColumn()
+ {
+
+ }
+
+ /**
+ *
+ * @OA\Get(path="/project-column/get-column-list",
+ * summary="Получить список колнок по проекту",
+ * description="Метод для получения колонок по проекту",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ * @OA\Parameter(
+ * name="project_id",
+ * in="query",
+ * required=true,
+ * @OA\Schema(
+ * type="integer",
+ * )
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает массив объектов Колонка",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/ProjectColumnExample"),
+ * ),
+ * ),
+ * )
+ *
+ * @param $project_id
+ * @return array|\yii\db\ActiveRecord[]
+ * @throws BadRequestHttpException
+ */
+ public function actionGetColumnList($project_id)
+ {
+ $project = Project::findOne($project_id);
+ if (!$project) {
+ throw new BadRequestHttpException(json_encode(['Проект не найден']));
+ }
+
+ $columns = \frontend\modules\api\models\ProjectColumn::find()->where(['project_id' => $project_id])->all();
+
+ return $columns;
+
+ }
+
+ /**
+ *
+ * @OA\Post(path="/project-column/create-column",
+ * summary="Добавить колонку",
+ * description="Метод для создания колонки",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ *
+ * @OA\RequestBody(
+ * @OA\MediaType(
+ * mediaType="multipart/form-data",
+ * @OA\Schema(
+ * required={"project_id", "title"},
+ * @OA\Property(
+ * property="project_id",
+ * type="integer",
+ * description="Идентификатор проекта",
+ * ),
+ * @OA\Property(
+ * property="title",
+ * type="string",
+ * description="Название колонки",
+ * ),
+ * ),
+ * ),
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает объект колонки",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/ProjectColumn"),
+ * ),
+ * ),
+ * )
+ *
+ * @return array|ProjectColumn
+ */
+ public function actionCreateColumn()
+ {
+ $column = new ProjectColumn();
+ $column->load(\Yii::$app->request->post(), '');
+
+ if ($column->validate()) {
+ $column->save(false);
+ return $column;
+ }
+ return $column->errors;
+
+ }
+
+ public function actionUpdateColumn()
+ {
+
+ }
+
+}
\ No newline at end of file
diff --git a/frontend/modules/api/controllers/ProjectController.php b/frontend/modules/api/controllers/ProjectController.php
index 8b7196b..e317d62 100644
--- a/frontend/modules/api/controllers/ProjectController.php
+++ b/frontend/modules/api/controllers/ProjectController.php
@@ -2,6 +2,7 @@
namespace frontend\modules\api\controllers;
+use common\classes\Debug;
use common\models\ProjectTaskCategory;
use common\models\ProjectUser;
use common\models\Status;
@@ -10,6 +11,7 @@ use frontend\modules\api\models\Project;
use Yii;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
+use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
class ProjectController extends ApiController
@@ -38,9 +40,49 @@ class ProjectController extends ApiController
]);
}
- public function actionGetProject($project_id): ?Project
+ /**
+ *
+ * @OA\Get(path="/project/get-project",
+ * summary="Получить данные проекта",
+ * description="Метод для получения проета",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ * @OA\Parameter(
+ * name="project_id",
+ * in="query",
+ * required=true,
+ * @OA\Schema(
+ * type="integer",
+ * default=null
+ * )
+ * ),
+ * @OA\Parameter(
+ * name="expand",
+ * in="query",
+ * required=false,
+ * description="В этом параметре по необходимости передаются поля, которые нужно добавить в ответ сервера, сейчас доступно только поле columns",
+ * @OA\Schema(
+ * type="string",
+ * )
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает массив объектов проекта",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/Project"),
+ * ),
+ * ),
+ * )
+ *
+ * @param $project_id
+ * @return array|Project|\yii\db\ActiveRecord|null
+ */
+ public function actionGetProject($project_id)
{
- return Project::findOne($project_id);
+ return Project::find()->with('columns')->where(['id' => $project_id])->one();
}
/**
@@ -61,7 +103,16 @@ class ProjectController extends ApiController
* default=null
* )
* ),
-
+ * @OA\Parameter(
+ * name="expand",
+ * in="query",
+ * required=false,
+ * description="В этом параметре по необходимости передаются поля, которые нужно добавить в ответ сервера, сейчас доступно только поле columns",
+ * @OA\Schema(
+ * type="string",
+ * )
+ * ),
+ *
* @OA\Response(
* response=200,
* description="Возвращает массив объектов проекта",
@@ -134,10 +185,66 @@ class ProjectController extends ApiController
return $projectTaskCategory;
}
+ /**
+ *
+ * @OA\Post(path="/project/create",
+ * summary="Добавить проект",
+ * description="Метод для создания проекта, если не передан параметр user_id, то будет получен текущий пользователь",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ *
+ * @OA\RequestBody(
+ * @OA\MediaType(
+ * mediaType="multipart/form-data",
+ * @OA\Schema(
+ * required={"name", "status"},
+ * @OA\Property(
+ * property="name",
+ * type="string",
+ * description="Название проекта",
+ * ),
+ * @OA\Property(
+ * property="description",
+ * type="string",
+ * description="Описание проекта",
+ * ),
+ * @OA\Property(
+ * property="status",
+ * type="integer",
+ * description="статус",
+ * ),
+ * @OA\Property(
+ * property="company_id",
+ * type="integer",
+ * description="Компания к которой относится проект",
+ * ),
+ * ),
+ * ),
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает объект Проекта",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/Project"),
+ * ),
+ * ),
+ * )
+ *
+ * @return array|Project
+ * @throws BadRequestHttpException
+ */
public function actionCreate()
{
$project = new Project();
- $project->attributes = \yii::$app->request->post();
+ $user_id = \Yii::$app->user->id;
+ if (!$user_id) {
+ throw new BadRequestHttpException(json_encode(['Пользователь не найден']));
+ }
+ $project->load(\yii::$app->request->post(), '');
+ $project->owner_id = $user_id;
if($project->validate()) {
$project->save(false);
diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php
index 4bd1642..5ad05dd 100644
--- a/frontend/modules/api/controllers/TaskController.php
+++ b/frontend/modules/api/controllers/TaskController.php
@@ -16,6 +16,7 @@ class TaskController extends ApiController
return [
'get-task' => ['get'],
'get-task-list' => ['get'],
+ 'get-user-tasks' => ['get'],
'create-task' => ['post'],
'update-task' => ['put', 'patch'],
];
@@ -36,9 +37,35 @@ class TaskController extends ApiController
/**
+ *
+ * @OA\Get(path="/task/get-task-list",
+ * summary="Получить список задач по проекту",
+ * description="Метод для получения задач по проекту",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ * @OA\Parameter(
+ * name="project_id",
+ * in="query",
+ * required=true,
+ * @OA\Schema(
+ * type="integer",
+ * )
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает массив объектов Задач",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/ProjectTaskExample"),
+ * ),
+ * ),
+ * )
+ *
* @throws NotFoundHttpException
*/
- public function actionGetTaskList($project_id = null): array
+ public function actionGetTaskList($project_id): array
{
$tasks = array();
if ($project_id) {
@@ -56,6 +83,55 @@ class TaskController extends ApiController
return $tasks;
}
+ /**
+ *
+ * @OA\Get(path="/task/get-user-tasks",
+ * summary="Получить список задач по пользователю",
+ * description="Метод для получения задач по пользователю",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ * @OA\Parameter(
+ * name="user_id",
+ * in="query",
+ * required=true,
+ * @OA\Schema(
+ * type="integer",
+ * )
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает массив объектов Задач",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/ProjectTaskExample"),
+ * ),
+ * ),
+ * )
+ *
+ * @param $user_id
+ * @return array
+ * @throws NotFoundHttpException
+ */
+ public function actionGetUserTasks($user_id): array
+ {
+ $tasks = array();
+ if ($user_id) {
+ if (empty($user_id) or !is_numeric($user_id)) {
+ throw new NotFoundHttpException('Incorrect project ID');
+ }
+ $tasks = TaskService::getTaskListByUser($user_id);
+ } else {
+ $tasks = TaskService::getTaskList($user_id);
+ }
+
+ if (empty($tasks)) {
+ throw new NotFoundHttpException('The project does not exist or there are no tasks for it');
+ }
+ return $tasks;
+ }
+
/**
* @throws NotFoundHttpException
*/
diff --git a/frontend/modules/api/models/Project.php b/frontend/modules/api/models/Project.php
index 44ffd9b..a975e17 100644
--- a/frontend/modules/api/models/Project.php
+++ b/frontend/modules/api/models/Project.php
@@ -14,7 +14,7 @@ use yii\web\Linkable;
* @OA\Property(
* property="id",
* type="int",
- * example=1,
+ * example=95,
* description="Идентификатор проекта"
* ),
* @OA\Property(
@@ -45,6 +45,10 @@ use yii\web\Linkable;
* property="company",
* ref="#/components/schemas/Company",
* ),
+ * @OA\Property(
+ * property="columns",
+ * ref="#/components/schemas/ProjectColumnExample",
+ * ),
*)
*
* @OA\Schema(
@@ -100,13 +104,14 @@ class Project extends \common\models\Project
'owner_id',
'company' => function() {
return $this->company;
- }
+ },
+
];
}
public function extraFields(): array
{
- return [];
+ return ['columns',];
}
public function getLinks(): array
diff --git a/frontend/modules/api/models/ProjectColumn.php b/frontend/modules/api/models/ProjectColumn.php
new file mode 100644
index 0000000..341eeb8
--- /dev/null
+++ b/frontend/modules/api/models/ProjectColumn.php
@@ -0,0 +1,95 @@
+