swagger tasks

This commit is contained in:
2023-04-26 01:22:02 +03:00
parent 226f2daa34
commit 50b9722e82
6 changed files with 242 additions and 8 deletions

View File

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

View File

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