update get-task-list method

This commit is contained in:
iIronside 2023-11-22 16:39:51 +03:00
parent 835147af37
commit cd9f828f60
2 changed files with 18 additions and 4 deletions

View File

@ -147,6 +147,15 @@ class TaskController extends ApiController
* ) * )
* ), * ),
* @OA\Parameter( * @OA\Parameter(
* name="user_id",
* description="При передаче этого параметера вернёт все задачи на проекте для пользователя с заданным id",
* in="query",
* required=false,
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="expand", * name="expand",
* in="query", * in="query",
* example="column,timers,mark", * example="column,timers,mark",
@ -167,9 +176,9 @@ class TaskController extends ApiController
* *
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionGetTaskList($project_id): array public function actionGetTaskList($project_id, $user_id = null): array
{ {
$tasks = $this->taskService->getTaskListByProject($project_id); $tasks = $this->taskService->getTaskListByProject($project_id, $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

@ -35,9 +35,14 @@ class TaskService
return ProjectTask::find()->asArray()->all(); return ProjectTask::find()->asArray()->all();
} }
public function getTaskListByProject($project_id): array public function getTaskListByProject($project_id, $user_id): array
{ {
return ProjectTask::find()->where(['project_id' => $project_id])->orderBy('priority DESC')->all(); $query = ProjectTask::find()->where(['project_id' => $project_id]);
if ($user_id) {
$query->andWhere(['user_id' => $user_id]);
}
return $query->orderBy('priority DESC')->all();
} }
public function getArchiveTask($project_id, $user_id): array public function getArchiveTask($project_id, $user_id): array