1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TestMonitor\DoneDone\Actions; |
4
|
|
|
|
5
|
|
|
use TestMonitor\DoneDone\Resources\Task; |
6
|
|
|
use TestMonitor\DoneDone\Transforms\TransformsTasks; |
7
|
|
|
use TestMonitor\DoneDone\Responses\PaginatedResponse; |
8
|
|
|
|
9
|
|
|
trait ManagesTasks |
10
|
|
|
{ |
11
|
|
|
use TransformsTasks; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Get a list of of tasks. |
15
|
|
|
* |
16
|
|
|
* @param int $accountId |
17
|
|
|
* @param int $projectId |
18
|
|
|
* @param string $query |
19
|
|
|
* @param int $page |
20
|
|
|
* @return \TestMonitor\DoneDone\Responses\PaginatedResponse |
21
|
|
|
*/ |
22
|
5 |
|
public function tasks(int $accountId, int $projectId, string $query = '', int $page = 1): PaginatedResponse |
23
|
|
|
{ |
24
|
5 |
|
$result = $this->get("{$accountId}/tasks/all", [ |
|
|
|
|
25
|
5 |
|
'query' => [ |
26
|
5 |
|
'internal_project_ids' => $projectId, |
27
|
5 |
|
'search_term' => $query, |
28
|
5 |
|
'page' => $page, |
29
|
5 |
|
], |
30
|
5 |
|
]); |
31
|
|
|
|
32
|
1 |
|
return new PaginatedResponse( |
33
|
1 |
|
items: array_map(fn ($task) => $this->fromDoneDoneTask($task), $result['listTasks']) ?? [], |
34
|
1 |
|
total: $result['totalTaskCount'], |
35
|
1 |
|
perPage: $result['itemsPerPage'], |
36
|
1 |
|
currentPage: $result['page'], |
37
|
1 |
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get a single task. |
42
|
|
|
* |
43
|
|
|
* @param int $id |
44
|
|
|
* @param int $accountId |
45
|
|
|
* @param int $projectId |
46
|
|
|
* @return Task |
47
|
|
|
*/ |
48
|
2 |
|
public function task(int $id, int $accountId, int $projectId): Task |
49
|
|
|
{ |
50
|
2 |
|
$result = $this->get("{$accountId}/internal-projects/{$projectId}/tasks/{$id}"); |
51
|
|
|
|
52
|
2 |
|
return $this->fromDoneDoneTask($result); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Create a new task. |
57
|
|
|
* |
58
|
|
|
* @param \TestMonitor\DoneDone\Resources\Task $task |
59
|
|
|
* @param int $accountId |
60
|
|
|
* @param int $projectId |
61
|
|
|
* @return Task |
62
|
|
|
*/ |
63
|
1 |
|
public function createTask(Task $task, int $accountId, int $projectId) |
64
|
|
|
{ |
65
|
1 |
|
$result = $this->post("{$accountId}/internal-projects/{$projectId}/tasks/", [ |
|
|
|
|
66
|
1 |
|
'json' => $this->toDoneDoneTask($task), |
67
|
1 |
|
]); |
68
|
|
|
|
69
|
1 |
|
return $this->task($result['id'], $accountId, $projectId); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|