swagger tasks
This commit is contained in:
parent
226f2daa34
commit
50b9722e82
@ -106,7 +106,7 @@ class Project extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->hasMany(ProjectColumn::class, ['project_id' => 'id'])->with('tasks');
|
||||
return $this->hasMany(ProjectColumn::class, ['project_id' => 'id'])->with('tasks')->where(['status' => ProjectColumn::STATUS_ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,6 +123,6 @@ class ProjectColumn extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getTasks()
|
||||
{
|
||||
return $this->hasMany(ProjectTask::class, ['column_id' => 'id'])->with('taskUsers');
|
||||
return $this->hasMany(ProjectTask::class, ['column_id' => 'id'])->with('taskUsers')->where(['status' => ProjectTask::STATUS_ACTIVE]);
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ use yii\helpers\ArrayHelper;
|
||||
*/
|
||||
class ProjectTask extends ActiveRecord
|
||||
{
|
||||
const STATUS_ACTIVE = 1;
|
||||
const STATUS_DISABLE = 0;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -103,6 +105,17 @@ class ProjectTask extends ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::STATUS_ACTIVE => 'Активен',
|
||||
self::STATUS_DISABLE => 'Выключен'
|
||||
];
|
||||
}
|
||||
|
||||
public function beforeDelete()
|
||||
{
|
||||
foreach ($this->taskUsers as $taskUser) {
|
||||
|
@ -2,7 +2,10 @@
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\classes\Debug;
|
||||
use common\models\ProjectTask;
|
||||
use common\models\ProjectTaskUser;
|
||||
use common\models\ProjectUser;
|
||||
|
||||
class TaskService
|
||||
{
|
||||
@ -31,7 +34,8 @@ class TaskService
|
||||
|
||||
public static function getTaskListByUser($user_id): array
|
||||
{
|
||||
return ProjectTask::find()->where(['user_id' => $user_id])->all();
|
||||
$taskIdList = ProjectTaskUser::find()->where(['user_id' => $user_id])->select('task_id')->column();
|
||||
return ProjectTask::find()->where([ 'IN', 'id', $taskIdList])->orWhere(['user_id' => $user_id])->all();
|
||||
}
|
||||
|
||||
public static function updateTask($task_params): ?ProjectTask
|
||||
|
@ -62,7 +62,7 @@ class ProjectColumnController extends ApiController
|
||||
throw new BadRequestHttpException(json_encode(['Проект не найден']));
|
||||
}
|
||||
|
||||
$columns = \frontend\modules\api\models\ProjectColumn::find()->where(['project_id' => $project_id])->all();
|
||||
$columns = \frontend\modules\api\models\ProjectColumn::find()->where(['project_id' => $project_id, 'status' => ProjectColumn::STATUS_ACTIVE])->all();
|
||||
|
||||
return $columns;
|
||||
|
||||
@ -121,9 +121,79 @@ class ProjectColumnController extends ApiController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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(
|
||||
* property="status",
|
||||
* type="integer",
|
||||
* description="Статус колонки",
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает объект Колонки",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/ProjectColumn"),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @return ProjectColumn|null
|
||||
* @throws BadRequestHttpException
|
||||
* @throws \yii\base\InvalidConfigException
|
||||
*/
|
||||
public function actionUpdateColumn()
|
||||
{
|
||||
$column_id = \Yii::$app->request->getBodyParam('column_id');
|
||||
if (!$column_id) {
|
||||
throw new BadRequestHttpException(json_encode(['Column not found']));
|
||||
}
|
||||
|
||||
$column = ProjectColumn::find()->where(['id' => $column_id, 'status' => ProjectColumn::STATUS_ACTIVE]);
|
||||
|
||||
$put = array_diff(\Yii::$app->request->getBodyParams(), [null, '']);
|
||||
|
||||
$column->load($put, '');
|
||||
|
||||
if (!$column->validate()){
|
||||
throw new BadRequestHttpException(json_encode($column->errors));
|
||||
}
|
||||
|
||||
$column->save(false);
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\classes\Debug;
|
||||
use common\models\ProjectTask;
|
||||
use common\services\TaskService;
|
||||
use Yii;
|
||||
@ -23,12 +24,74 @@ class TaskController extends ApiController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Post(path="/task/create-task",
|
||||
* summary="Добавить задачу",
|
||||
* description="Метод для создания задачи, если не передан параметр <b>user_id</b>, то будет получен текущий пользователь",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"TaskManager"},
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* @OA\MediaType(
|
||||
* mediaType="multipart/form-data",
|
||||
* @OA\Schema(
|
||||
* required={"project_id", "status", "title", "description"},
|
||||
* @OA\Property(
|
||||
* property="project_id",
|
||||
* type="string",
|
||||
* description="Идентификатор проекта",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="title",
|
||||
* type="string",
|
||||
* description="Заголовок задачи",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="description",
|
||||
* type="string",
|
||||
* description="Описание задачи",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="status",
|
||||
* type="integer",
|
||||
* description="статус",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="column_id",
|
||||
* type="integer",
|
||||
* description="Колонка к которой относится задача",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="user_id",
|
||||
* type="integer",
|
||||
* description="Идентификатор создателя задачи",
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает объект задачи",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/ProjectTask"),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function actionCreateTask(): ProjectTask
|
||||
{
|
||||
$taskModel = TaskService::createTask(Yii::$app->getRequest()->getBodyParams());
|
||||
$request = Yii::$app->getRequest()->getBodyParams();
|
||||
if(!isset($request['user_id']) or $request['user_id'] == null){
|
||||
$request['user_id'] = Yii::$app->user->id;
|
||||
}
|
||||
|
||||
$taskModel = TaskService::createTask($request);
|
||||
if ($taskModel->errors) {
|
||||
throw new ServerErrorHttpException(json_encode($taskModel->errors));
|
||||
}
|
||||
@ -133,6 +196,32 @@ class TaskController extends ApiController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Get(path="/task/get-task",
|
||||
* summary="Получить информацию по задаче",
|
||||
* description="Метод для получения данных по задаче",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"TaskManager"},
|
||||
* @OA\Parameter(
|
||||
* name="task_id",
|
||||
* in="query",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает объект Задачи",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/ProjectTask"),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetTask($task_id): ProjectTask
|
||||
@ -150,20 +239,78 @@ class TaskController extends ApiController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Put(path="/task/update-task",
|
||||
* summary="Редактировать задачу",
|
||||
* description="Метод для редактирования задачи",
|
||||
* security={
|
||||
* {"bearerAuth": {}}
|
||||
* },
|
||||
* tags={"TaskManager"},
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/x-www-form-urlencoded",
|
||||
* @OA\Schema(
|
||||
* required={"task_id"},
|
||||
* @OA\Property(
|
||||
* property="user_id",
|
||||
* type="integer",
|
||||
* description="Идентификатор пользователя",
|
||||
* nullable=false,
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="task_id",
|
||||
* type="integer",
|
||||
* description="Идентификатор задачи",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="title",
|
||||
* type="string",
|
||||
* description="Заголовок задачи",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="column_id",
|
||||
* type="integer",
|
||||
* description="Идентификатор колонки",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="status",
|
||||
* type="integer",
|
||||
* description="Статус запроса",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="description",
|
||||
* type="string",
|
||||
* description="Описание запроса",
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Возвращает объект Задачи",
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/ProjectTask"),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @throws ServerErrorHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionUpdate(): ?ProjectTask
|
||||
public function actionUpdateTask(): ?ProjectTask
|
||||
{
|
||||
$params = Yii::$app->request->getBodyParams();
|
||||
$params = array_diff(\Yii::$app->request->getBodyParams(), [null, '']);
|
||||
if (empty ($params['task_id']) or !TaskService::taskExists($params['task_id'])) {
|
||||
throw new NotFoundHttpException('The task does not exist');
|
||||
}
|
||||
|
||||
$modelTask = TaskService::updateTask($params);
|
||||
if (!empty($modelTask->hasErrors())) {
|
||||
throw new ServerErrorHttpException(json_encode('Bad params'));
|
||||
throw new ServerErrorHttpException(json_encode($modelTask->errors));
|
||||
}
|
||||
|
||||
return $modelTask;
|
||||
|
Loading…
x
Reference in New Issue
Block a user