project task fix

This commit is contained in:
Kavalar 2023-04-27 01:53:21 +03:00
parent 50b9722e82
commit 525dbda657
4 changed files with 164 additions and 6 deletions

View File

@ -19,6 +19,7 @@ use yii\helpers\ArrayHelper;
* @property string $updated_at
* @property int $column_id
* @property int $user_id
* @property int $executor_id
* @property string $description
*
* @property Project $project
@ -30,6 +31,7 @@ class ProjectTask extends ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0;
/**
* {@inheritdoc}
*/
@ -57,13 +59,14 @@ class ProjectTask extends ActiveRecord
{
return [
[['project_id', 'status', 'title', 'description',], 'required'],
[['project_id', 'status', 'column_id', 'user_id'], 'integer'],
[['project_id', 'status', 'column_id', 'user_id', 'executor_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
['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']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
[['executor_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['executor_id' => 'id']],
[['column_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectColumn::className(), 'targetAttribute' => ['column_id' => 'id']],
];
}
@ -83,6 +86,7 @@ class ProjectTask extends ActiveRecord
'description' => 'Описание',
'user_id' => 'Создатель задачи',
'column_id' => 'Колонка',
'executor_id' => 'Исполнитель',
];
}
@ -101,6 +105,23 @@ class ProjectTask extends ActiveRecord
'status',
'column_id',
'user_id',
'user' => function () {
return [
"fio" => $this->user->userCard->fio ?? $this->user->username,
"avatar" => $this->user->userCard->photo ?? '',
];
},
'executor_id',
'executor' => function () {
if ($this->executor){
return [
"fio" => $this->executor->userCard->fio ?? $this->executor->username,
"avatar" => $this->executor->userCard->photo ?? '',
];
}
return null;
},
'taskUsers',
];
}
@ -127,7 +148,7 @@ class ProjectTask extends ActiveRecord
/**
* @return ActiveQuery
*/
public function getProject()
public function getProject(): ActiveQuery
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}
@ -135,11 +156,19 @@ class ProjectTask extends ActiveRecord
/**
* @return ActiveQuery
*/
public function getUser()
public function getUser(): ActiveQuery
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return ActiveQuery
*/
public function getExecutor(): ActiveQuery
{
return $this->hasOne(User::class, ['id' => 'executor_id']);
}
/**
* @return ActiveQuery
*/

View File

@ -0,0 +1,42 @@
<?php
use yii\db\Migration;
/**
* Class m230426_221513_add_executor_id_to_project_task_table
*/
class m230426_221513_add_executor_id_to_project_task_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('project_task', 'executor_id', $this->integer(11));
$this->addForeignKey('fk_project_task_user_executor', 'project_task', 'executor_id', 'user', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('fk_project_task_user_executor', 'project_task');
$this->dropColumn('project_task', 'executor_id');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m230426_221513_add_executor_id_to_project_task_table cannot be reverted.\n";
return false;
}
*/
}

View File

@ -34,7 +34,7 @@ class ProjectController extends ApiController
'status-list' => ['GET', 'OPTIONS'],
'project-task-category-list' => ['GET', 'OPTIONS'],
'create' => ['POST', 'OPTIONS'],
'update' => ['POST', 'OPTIONS']
'update' => ['PUT', 'OPTIONS']
],
]
]);
@ -254,6 +254,58 @@ class ProjectController extends ApiController
}
/**
*
* @OA\PUT(path="/project/update",
* summary="Редактировать проект",
* description="Метод для редактирования проекта",
* security={
* {"bearerAuth": {}}
* },
* tags={"TaskManager"},
*
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* required={"project_id"},
* @OA\Property(
* property="project_id",
* type="integer",
* description="Идентификатор проекта",
* ),
* @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"),
* ),
* ),
* )
*
* @throws \Throwable
* @throws \yii\base\InvalidConfigException
* @throws \yii\db\StaleObjectException
@ -261,12 +313,17 @@ class ProjectController extends ApiController
*/
public function actionUpdate()
{
$project = Project::findOne(Yii::$app->request->post('project_id'));
$request = Yii::$app->request->getBodyParams();
if (!isset($request['project_id']) || $request['project_id'] == null){
throw new BadRequestHttpException(json_encode(['The project ID not found']));
}
$project = Project::findOne($request['project_id']);
if(empty($project)) {
throw new NotFoundHttpException('The project not found');
}
$project->load(Yii::$app->request->getBodyParams(), '');
$put = array_diff($request, [null, '']);
$project->load($put, '');
if (!$project->update()) {
return $project->errors;
}

View File

@ -34,9 +34,25 @@ namespace frontend\modules\api\models;
* property="user_id",
* type="int",
* example="19",
* description="Идентификатор пользователя создавшего задачу"
* ),
* @OA\Property(
* property="user",
* ref="#/components/schemas/ProjectTaskUsersShortExample",
* description="Пользователь создавший задачу"
* ),
* @OA\Property(
* property="executor_id",
* type="int",
* example="2",
* description="Идентификатор исполнителя задачи"
* ),
* @OA\Property(
* property="executor",
* ref="#/components/schemas/ProjectTaskUsersShortExample",
* description="Исполнитель задачи"
* ),
* @OA\Property(
* property="description",
* type="string",
* example="Описание задачи",
@ -97,6 +113,20 @@ namespace frontend\modules\api\models;
* ),
*)
*
* @OA\Schema(
* schema="ProjectTaskUsersShortExample",
* @OA\Property(
* property="fio",
* type="string",
* example="Сапронов Антон Викторович"
* ),
* @OA\Property(
* property="avatar",
* type="string",
* example="/profileava/m8.png"
* ),
*)
*
*/
class ProjectTask extends \common\models\ProjectTask
{