2023-04-25 01:32:15 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
use common\models\ProjectColumn;
|
2023-11-10 15:55:01 +03:00
|
|
|
use frontend\modules\api\models\project\Project;
|
|
|
|
use yii\db\ActiveRecord;
|
2023-04-25 01:32:15 +03:00
|
|
|
use yii\web\BadRequestHttpException;
|
2023-05-23 02:11:44 +03:00
|
|
|
use yii\web\NotFoundHttpException;
|
2023-04-25 01:32:15 +03:00
|
|
|
|
|
|
|
class ProjectColumnController extends ApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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
|
2023-11-10 15:55:01 +03:00
|
|
|
* @return array|ActiveRecord[]
|
2023-04-25 01:32:15 +03:00
|
|
|
* @throws BadRequestHttpException
|
|
|
|
*/
|
2023-11-10 15:55:01 +03:00
|
|
|
public function actionGetColumnList($project_id): array
|
2023-04-25 01:32:15 +03:00
|
|
|
{
|
|
|
|
$project = Project::findOne($project_id);
|
|
|
|
if (!$project) {
|
|
|
|
throw new BadRequestHttpException(json_encode(['Проект не найден']));
|
|
|
|
}
|
|
|
|
|
2023-11-10 15:55:01 +03:00
|
|
|
$columns = \frontend\modules\api\models\project\ProjectColumn::find()->where(['project_id' => $project_id, 'status' => ProjectColumn::STATUS_ACTIVE])->all();
|
2023-04-25 01:32:15 +03:00
|
|
|
|
|
|
|
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="Название колонки",
|
|
|
|
* ),
|
2023-05-11 01:18:40 +03:00
|
|
|
* @OA\Property(
|
|
|
|
* property="priority",
|
|
|
|
* type="integer",
|
|
|
|
* description="Приоритет колонки",
|
|
|
|
* ),
|
2023-04-25 01:32:15 +03:00
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-26 01:22:02 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @OA\Put(path="/project-column/update-column",
|
|
|
|
* summary="Редактировать колонку",
|
|
|
|
* description="Метод для редактирования колонки",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"TaskManager"},
|
|
|
|
*
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/x-www-form-urlencoded",
|
|
|
|
* @OA\Schema(
|
|
|
|
* required={"column_id"},
|
|
|
|
* @OA\Property(
|
|
|
|
* property="column_id",
|
|
|
|
* type="integer",
|
|
|
|
* description="Идентификатор колонки",
|
|
|
|
* nullable=false,
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="title",
|
|
|
|
* type="string",
|
|
|
|
* description="Название колонки",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="project_id",
|
|
|
|
* type="integer",
|
|
|
|
* description="Идентификатор проекта",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
2023-05-11 01:18:40 +03:00
|
|
|
* property="priority",
|
|
|
|
* type="integer",
|
|
|
|
* description="Приоритет колонки",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
2023-04-26 01:22:02 +03:00
|
|
|
* property="status",
|
|
|
|
* type="integer",
|
|
|
|
* description="Статус колонки",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает объект Колонки",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(ref="#/components/schemas/ProjectColumn"),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2023-11-10 15:55:01 +03:00
|
|
|
* @return array|ProjectColumn|ActiveRecord|null
|
2023-04-26 01:22:02 +03:00
|
|
|
* @throws BadRequestHttpException
|
|
|
|
* @throws \yii\base\InvalidConfigException
|
|
|
|
*/
|
2023-04-25 01:32:15 +03:00
|
|
|
public function actionUpdateColumn()
|
|
|
|
{
|
2023-04-26 01:22:02 +03:00
|
|
|
$column_id = \Yii::$app->request->getBodyParam('column_id');
|
|
|
|
if (!$column_id) {
|
|
|
|
throw new BadRequestHttpException(json_encode(['Column not found']));
|
|
|
|
}
|
|
|
|
|
2023-05-03 23:41:25 +03:00
|
|
|
$column = ProjectColumn::find()->where(['id' => $column_id, 'status' => ProjectColumn::STATUS_ACTIVE])->one();
|
2023-04-26 01:22:02 +03:00
|
|
|
|
|
|
|
$put = array_diff(\Yii::$app->request->getBodyParams(), [null, '']);
|
|
|
|
|
|
|
|
$column->load($put, '');
|
|
|
|
|
2023-05-23 02:11:44 +03:00
|
|
|
if (!$column->validate()) {
|
2023-04-26 01:22:02 +03:00
|
|
|
throw new BadRequestHttpException(json_encode($column->errors));
|
|
|
|
}
|
|
|
|
|
|
|
|
$column->save(false);
|
2023-04-25 01:32:15 +03:00
|
|
|
|
2023-04-26 01:22:02 +03:00
|
|
|
return $column;
|
2023-04-25 01:32:15 +03:00
|
|
|
}
|
|
|
|
|
2023-05-23 02:11:44 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @OA\Post(path="/project-column/set-priority",
|
|
|
|
* summary="Установить приоритет колонок",
|
|
|
|
* description="Метод для установления приоритета колонок в проекте",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"TaskManager"},
|
|
|
|
*
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="multipart/form-data",
|
|
|
|
* @OA\Schema(
|
|
|
|
* required={"project_id", "data"},
|
|
|
|
* @OA\Property(
|
|
|
|
* property="project_id",
|
|
|
|
* type="integer",
|
|
|
|
* description="Идентификатор проекта",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="data",
|
|
|
|
* type="string",
|
|
|
|
* description="Данные для обновления приоритета. Пример: [{"column_id":1,"priority":2},{"column_id":2,"priority":3}]",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает объект проекта",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(ref="#/components/schemas/Project"),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2023-11-10 15:55:01 +03:00
|
|
|
* @return array|Project|ActiveRecord
|
2023-05-23 02:11:44 +03:00
|
|
|
* @throws BadRequestHttpException
|
|
|
|
*/
|
|
|
|
public function actionSetPriority()
|
|
|
|
{
|
|
|
|
$request = \Yii::$app->request->post();
|
|
|
|
$data = $request['data'];
|
|
|
|
|
|
|
|
$project = Project::findOne($request['project_id']);
|
|
|
|
if (empty($project)) {
|
|
|
|
throw new NotFoundHttpException('The project not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$data = json_decode($data, true)) {
|
|
|
|
throw new BadRequestHttpException('No valid JSON');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($data as $datum) {
|
|
|
|
$model = ProjectColumn::findOne($datum['column_id']);
|
|
|
|
$model->priority = $datum['priority'];
|
|
|
|
if (!$model->validate()){
|
|
|
|
throw new BadRequestHttpException($model->errors);
|
|
|
|
}
|
|
|
|
$model->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $project;
|
|
|
|
}
|
|
|
|
|
2023-04-25 01:32:15 +03:00
|
|
|
}
|