add api/task/get-archive-task method

This commit is contained in:
iIronside 2023-11-20 11:39:44 +03:00
parent 886ba1e656
commit 91607cc99b
5 changed files with 73 additions and 23 deletions

View File

@ -2,10 +2,8 @@
namespace backend\modules\task\models; namespace backend\modules\task\models;
use backend\modules\project\models\ProjectUser;
use yii\base\Model; use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use backend\modules\task\models\ProjectTask;
/** /**
* TaskSearch represents the model behind the search form of `backend\modules\task\models\Task`. * TaskSearch represents the model behind the search form of `backend\modules\task\models\Task`.

View File

@ -38,8 +38,9 @@ use yii\helpers\ArrayHelper;
*/ */
class ProjectTask extends ActiveRecord class ProjectTask extends ActiveRecord
{ {
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0; const STATUS_DISABLE = 0;
const STATUS_ACTIVE = 1;
const STATUS_ARCHIVE = 2;
const PRIORITY_LOW = 0; const PRIORITY_LOW = 0;
const PRIORITY_MEDIUM = 1; const PRIORITY_MEDIUM = 1;
@ -101,6 +102,7 @@ class ProjectTask extends ActiveRecord
['execution_priority', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]], ['execution_priority', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]],
['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
['status', 'in', 'range' => [self::STATUS_DISABLE, self::STATUS_ACTIVE, self::STATUS_ARCHIVE]],
[['description'], 'string', 'max' => 1500], [['description'], 'string', 'max' => 1500],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],

View File

@ -16,6 +16,9 @@ use yii\web\ServerErrorHttpException;
class TaskController extends ApiController class TaskController extends ApiController
{ {
/**
* @var TaskService
*/
private TaskService $taskService; private TaskService $taskService;
/** /**
@ -166,15 +169,7 @@ class TaskController extends ApiController
*/ */
public function actionGetTaskList($project_id): array public function actionGetTaskList($project_id): array
{ {
$tasks = array(); $tasks = $this->taskService->getTaskListByProject($project_id);
if ($project_id) {
if (empty($project_id) or !is_numeric($project_id)) {
throw new NotFoundHttpException('Incorrect project ID');
}
$tasks = $this->taskService->getTaskListByProject($project_id);
} else {
$tasks = $this->taskService->getTaskList($project_id);
}
if (empty($tasks)) { if (empty($tasks)) {
throw new NotFoundHttpException('The project does not exist or there are no tasks for it'); throw new NotFoundHttpException('The project does not exist or there are no tasks for it');
@ -182,6 +177,59 @@ class TaskController extends ApiController
return $tasks; return $tasks;
} }
/**
*
* @OA\Get(path="/task/get-archive-task",
* summary="Получить список архивных задач по проекту",
* description="Метод для получения архивных задач по проекту",
* security={
* {"bearerAuth": {}}
* },
* tags={"TaskManager"},
* @OA\Parameter(
* name="project_id",
* in="query",
* required=true,
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="user_id",
* in="query",
* required=false,
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="expand",
* in="query",
* example="column,timers,mark",
* description="В этом параметре по необходимости передаются поля, которые нужно добавить в ответ сервера, сейчас доступно только поля <b>column</b>, <b>timers</b> и <b>mark</b>",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Response(
* response=200,
* description="Возвращает массив объектов Задач",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ProjectTaskExample"),
* ),
* ),
* )
*
* @param $project_id
* @param null $user_id
* @return array
*/
public function actionGetArchiveTask($project_id, $user_id = null): array
{
return $this->taskService->getArchiveTask($project_id, $user_id);
}
/** /**
* *
* @OA\Get(path="/task/get-user-tasks", * @OA\Get(path="/task/get-user-tasks",
@ -224,15 +272,7 @@ class TaskController extends ApiController
*/ */
public function actionGetUserTasks($user_id): array public function actionGetUserTasks($user_id): array
{ {
$tasks = array(); $tasks = $this->taskService->getTaskListByUser($user_id);
if ($user_id) {
if (empty($user_id) or !is_numeric($user_id)) {
throw new NotFoundHttpException('Incorrect project ID');
}
$tasks = $this->taskService->getTaskListByUser($user_id);
} else {
$tasks = $this->taskService->getTaskList($user_id);
}
if (empty($tasks)) { if (empty($tasks)) {
throw new NotFoundHttpException('The project does not exist or there are no tasks for it'); throw new NotFoundHttpException('The project does not exist or there are no tasks for it');

View File

@ -80,7 +80,7 @@ namespace frontend\modules\api\models\project;
* property="status", * property="status",
* type="int", * type="int",
* example="1", * example="1",
* description="Статус задачи" * description="Статус задачи(0 - disable, 1 - active, 2 - archive)"
* ), * ),
* @OA\Property( * @OA\Property(
* property="comment_count", * property="comment_count",

View File

@ -30,7 +30,7 @@ class TaskService
return ProjectTask::findOne($task_id); return ProjectTask::findOne($task_id);
} }
public function getTaskList($task_id): array public function getTaskList($status = null): array
{ {
return ProjectTask::find()->asArray()->all(); return ProjectTask::find()->asArray()->all();
} }
@ -40,6 +40,16 @@ class TaskService
return ProjectTask::find()->where(['project_id' => $project_id])->orderBy('priority DESC')->all(); return ProjectTask::find()->where(['project_id' => $project_id])->orderBy('priority DESC')->all();
} }
public function getArchiveTask($project_id, $user_id): array
{
$query = ProjectTask::find()->where(['project_id' => $project_id])->andWhere(['status' => ProjectTask::STATUS_ARCHIVE]);
if ($user_id) {
$query->andWhere(['user_id' => $user_id]);
}
return $query->orderBy('priority DESC')->all();
}
public function getTaskListByUser($user_id): array public function getTaskListByUser($user_id): array
{ {
$taskIdList = ProjectTaskUser::find()->where(['user_id' => $user_id])->select('task_id')->column(); $taskIdList = ProjectTaskUser::find()->where(['user_id' => $user_id])->select('task_id')->column();