add import tasks to xlsx

This commit is contained in:
iIronside
2023-11-10 15:55:01 +03:00
parent bc4cb3b54c
commit 05271d5f17
20 changed files with 542 additions and 116 deletions

View File

@ -2,31 +2,32 @@
namespace frontend\modules\api\controllers;
use common\classes\Debug;
use common\models\ProjectTask;
use common\models\ProjectTaskUser;
use common\models\User;
use common\services\TaskService;
use frontend\modules\api\models\ProjectColumn;
use frontend\modules\api\models\project\ProjectColumn;
use frontend\modules\api\services\TaskService;
use Yii;
use yii\base\InvalidConfigException;
use yii\data\ActiveDataProvider;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
use yii\web\ServerErrorHttpException;
class TaskController extends ApiController
{
public function verbs(): array
private TaskService $taskService;
/**
* @param $id
* @param $module
* @param TaskService $taskService
* @param array $config
*/
public function __construct($id, $module, TaskService $taskService, $config = [])
{
return [
'get-task' => ['get'],
'get-task-list' => ['get'],
'get-user-tasks' => ['get'],
'create-task' => ['post'],
'update-task' => ['put', 'patch'],
'add-user-to-task' => ['post'],
'del-user' => ['delete'],
];
$this->taskService = $taskService;
parent::__construct($id, $module, $config);
}
/**
@ -117,7 +118,7 @@ class TaskController extends ApiController
$request['user_id'] = Yii::$app->user->id;
}
$taskModel = TaskService::createTask($request);
$taskModel = $this->taskService->createTask($request);
if ($taskModel->errors) {
throw new ServerErrorHttpException(json_encode($taskModel->errors));
}
@ -170,9 +171,9 @@ class TaskController extends ApiController
if (empty($project_id) or !is_numeric($project_id)) {
throw new NotFoundHttpException('Incorrect project ID');
}
$tasks = TaskService::getTaskListByProject($project_id);
$tasks = $this->taskService->getTaskListByProject($project_id);
} else {
$tasks = TaskService::getTaskList($project_id);
$tasks = $this->taskService->getTaskList($project_id);
}
if (empty($tasks)) {
@ -228,9 +229,9 @@ class TaskController extends ApiController
if (empty($user_id) or !is_numeric($user_id)) {
throw new NotFoundHttpException('Incorrect project ID');
}
$tasks = TaskService::getTaskListByUser($user_id);
$tasks = $this->taskService->getTaskListByUser($user_id);
} else {
$tasks = TaskService::getTaskList($user_id);
$tasks = $this->taskService->getTaskList($user_id);
}
if (empty($tasks)) {
@ -283,7 +284,7 @@ class TaskController extends ApiController
throw new NotFoundHttpException('Incorrect task ID');
}
$task = TaskService::getTask($task_id);
$task = $this->taskService->getTask($task_id);
if (empty($task)) {
throw new NotFoundHttpException('The task does not exist');
}
@ -372,11 +373,11 @@ class TaskController extends ApiController
public function actionUpdateTask(): ?ProjectTask
{
$params = array_diff(\Yii::$app->request->getBodyParams(), [null, '']);
if (empty ($params['task_id']) or !TaskService::taskExists($params['task_id'])) {
if (empty ($params['task_id']) or !$this->taskService->taskExists($params['task_id'])) {
throw new NotFoundHttpException('The task does not exist');
}
$modelTask = TaskService::updateTask($params);
$modelTask = $this->taskService->updateTask($params);
if (!empty($modelTask->hasErrors())) {
throw new ServerErrorHttpException(json_encode($modelTask->errors));
}
@ -435,7 +436,7 @@ class TaskController extends ApiController
throw new NotFoundHttpException('User not found');
}
if (empty ($request['task_id']) or !TaskService::taskExists($request['task_id'])) {
if (empty ($request['task_id']) or !$this->taskService->taskExists($request['task_id'])) {
throw new NotFoundHttpException('The task does not exist');
}
@ -506,13 +507,13 @@ class TaskController extends ApiController
throw new NotFoundHttpException('User not found');
}
if (empty ($request['task_id']) or !TaskService::taskExists($request['task_id'])) {
if (empty ($request['task_id']) or !$this->taskService->taskExists($request['task_id'])) {
throw new NotFoundHttpException('The task does not exist');
}
ProjectTaskUser::deleteAll(['task_id' => $request['task_id'], 'user_id' => $request['user_id']]);
return TaskService::getTask($request['task_id']);
return $this->taskService->getTask($request['task_id']);
}
/**
@ -582,4 +583,72 @@ class TaskController extends ApiController
return $column;
}
/**
*
* @OA\Get(path="/task/import",
* summary="Экспорт задач",
* description="Метод экспорта задач в xlsx",
* security={
* {"bearerAuth": {}}
* },
* tags={"TaskManager"},
* @OA\Parameter(
* name="companyId",
* in="query",
* description="ID компании",
* required=true,
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="userId",
* in="query",
* description="ID исполнителя задачи",
* required=true,
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="projectId",
* in="query",
* description="ID проекта",
* required=true,
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="fromDate",
* in="query",
* example="2023-11-09",
* description="Поиск задач с указанной даты",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="toDate",
* in="query",
* example="2023-11-09",
* description="Поиск задач до указанной даты",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Response(
* response=200,
* description="Возвращает задачи в xlsx файле",
* ),
* )
*
* @return string|void
* @throws BadRequestHttpException
*/
public function actionImport()
{
return $this->taskService->importTasks(Yii::$app->request->get());
}
}