task manager

This commit is contained in:
2023-04-25 01:32:15 +03:00
parent 5508fcb1ee
commit 226f2daa34
18 changed files with 746 additions and 85 deletions

View File

@ -0,0 +1,129 @@
<?php
namespace frontend\modules\api\controllers;
use common\models\ProjectColumn;
use frontend\modules\api\models\Project;
use yii\web\BadRequestHttpException;
class ProjectColumnController extends ApiController
{
public function verbs(): array
{
return [
'get-column' => ['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()
{
}
}

View File

@ -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="В этом параметре по необходимости передаются поля, которые нужно добавить в ответ сервера, сейчас доступно только поле <b>columns</b>",
* @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="В этом параметре по необходимости передаются поля, которые нужно добавить в ответ сервера, сейчас доступно только поле <b>columns</b>",
* @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="Метод для создания проекта, если не передан параметр <b>user_id</b>, то будет получен текущий пользователь",
* 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);

View File

@ -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
*/

View File

@ -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

View File

@ -0,0 +1,95 @@
<?php
namespace frontend\modules\api\models;
/**
*
* @OA\Schema(
* schema="ProjectColumn",
* @OA\Property(
* property="id",
* type="int",
* example=95,
* description="Идентификатор колонки"
* ),
* @OA\Property(
* property="title",
* type="string",
* example="Задачи на проверку",
* description="Название колонки"
* ),
* @OA\Property(
* property="project_id",
* type="int",
* example="95",
* description="Проект к которому относится колонка"
* ),
* @OA\Property(
* property="status",
* type="int",
* example="1",
* description="Статус колонки"
* ),
* @OA\Property(
* property="tasks",
* ref="#/components/schemas/ProjectTask",
* ),
*)
*
* @OA\Schema(
* schema="ProjectColumnExample",
* type="array",
* example={
* {"id": 1, "title": "Задачи на проверку", "project_id": 95, "status": 1,
* "tasks": {
* {"id": 95, "title": "Сложная задача", "project_id": 44, "column_id": 1, "user_id": 19, "description": "Описание задачи", "status": 1,
* "taskUsers": {
* {"id": 2, "task_id": 95, "user_id": 2, "fio": "Сапронов Антон Викторович", "avatar": "/profileava/m8.png"},
* {"id": 3, "task_id": 95, "user_id": 3, "fio": "Иванов Иван Иванович", "avatar": "/profileava/m2.png"},
* }
* },
* {"id": 96, "title": "Простая задача", "project_id": 44, "column_id": 1, "user_id": 19, "description": "Описание простой задачи", "status": 1,
* "taskUsers": {
* {"id": 3, "task_id": 96, "user_id": 3, "fio": "Иванов Иван Иванович", "avatar": "/profileava/m2.png"},
* {"id": 4, "task_id": 96, "user_id": 4, "fio": "Петров Петр Петрович", "avatar": "/profileava/m7.png"},
* }
* }
* }
* },
* {"id": 2, "title": "Новые задачи", "project_id": 95, "status": 1,
* "tasks": {
* {"id": 97, "title": "Очень Сложная задача", "project_id": 44, "column_id": 2, "user_id": 19, "description": "Описание простой задачи", "status": 1},
* {"id": 98, "title": "Очень Простая задача", "project_id": 44, "column_id": 2, "user_id": 19, "description": "Описание очень простой задачи", "status": 1}
* }
* }
* },
* @OA\Items(
* type="object",
* @OA\Property(
* property="id",
* type="int",
* ),
* @OA\Property(
* property="title",
* type="string",
* ),
* @OA\Property(
* property="project_id",
* type="int",
* ),
* @OA\Property(
* property="status",
* type="int",
* ),
* @OA\Property(
* property="tasks",
* ref="#/components/schemas/ProjectTask",
* ),
* ),
*)
*
*/
class ProjectColumn extends \common\models\ProjectColumn
{
}

View File

@ -0,0 +1,104 @@
<?php
namespace frontend\modules\api\models;
/**
*
* @OA\Schema(
* schema="ProjectTask",
* @OA\Property(
* property="id",
* type="int",
* example=95,
* description="Идентификатор задачи"
* ),
* @OA\Property(
* property="title",
* type="string",
* example="Задачи на проверку",
* description="Заголовок задачи"
* ),
* @OA\Property(
* property="project_id",
* type="int",
* example="95",
* description="Проект к которому относится задача"
* ),
* @OA\Property(
* property="column_id",
* type="int",
* example="23",
* description="Колонка к которой относится задача"
* ),
* @OA\Property(
* property="user_id",
* type="int",
* example="19",
* description="Пользователь создавший задачу"
* ),
* @OA\Property(
* property="description",
* type="string",
* example="Описание задачи",
* description="Описание задачи"
* ),
* @OA\Property(
* property="status",
* type="int",
* example="1",
* description="Статус колонки"
* ),
* @OA\Property(
* property="taskUsers",
* ref="#/components/schemas/ProjectTaskUsersExample",
* ),
*)
*
* @OA\Schema(
* schema="ProjectTaskExample",
* type="array",
* @OA\Items(
* type="object",
* ref="#/components/schemas/ProjectTask",
* ),
*)
*
*
* @OA\Schema(
* schema="ProjectTaskUsersExample",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="id",
* type="integer",
* example="1"
* ),
* @OA\Property(
* property="task_id",
* type="integer",
* example="1"
* ),
* @OA\Property(
* property="user_id",
* type="integer",
* example="19"
* ),
* @OA\Property(
* property="fio",
* type="string",
* example="Сапронов Антон Викторович"
* ),
* @OA\Property(
* property="avatar",
* type="string",
* example="/profileava/m8.png"
* ),
* ),
*)
*
*/
class ProjectTask extends \common\models\ProjectTask
{
}

View File

@ -1,6 +1,7 @@
<?php
namespace frontend\modules\api\models;
/**
* @OA\Schema(
* schema="Skill",