Skip to content

Commit e01f543

Browse files
ppaczTomáš Lipenský
andauthored
feat: added endpoint to find workload by ID (#537)
Co-authored-by: Tomáš Lipenský <[email protected]>
1 parent fb62c0e commit e01f543

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/ServiceDesk/Request/RequestService.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,26 @@ public function getWorklogById(string $issueIdOrKey, int $workLogId): Worklog
427427
);
428428
}
429429

430+
/**
431+
* @param array<int> $ids
432+
*
433+
* @return array<Worklog>
434+
*/
435+
public function getWorklogsByIds(array $ids): array
436+
{
437+
$ret = $this->client->exec('/worklog/list', json_encode(['ids' => $ids]), 'POST');
438+
439+
$this->logger->debug("getWorklogsByIds res=$ret\n");
440+
441+
$worklogsResponse = json_decode($ret, false, 512, JSON_THROW_ON_ERROR);
442+
443+
$worklogs = array_map(function ($worklog) {
444+
return $this->jsonMapper->map($worklog, new Worklog());
445+
}, $worklogsResponse);
446+
447+
return $worklogs;
448+
}
449+
430450
/**
431451
* add work log to issue.
432452
*

tests/ServiceDesk/Request/RequestServiceTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,33 @@ public function testGetWorklogById(): void
369369
self::assertSame($item->timeSpent, $result->timeSpent);
370370
}
371371

372+
public function testGetWorklogsByIds(): void
373+
{
374+
$item1 = new stdClass();
375+
$item1->id = 25;
376+
$item1->timeSpent = '2 hours';
377+
378+
$item2 = new stdClass();
379+
$item2->id = 50;
380+
$item2->timeSpent = '2 hours';
381+
382+
383+
$items = [
384+
$item1,
385+
$item2,
386+
];
387+
388+
$this->client->method('exec')
389+
->with("/worklog/list", json_encode(['ids' => [25, 50]]), 'POST')
390+
->willReturn(json_encode($items));
391+
392+
$result = $this->uut->getWorklogsByIds([25, 50]);
393+
394+
self::assertSame(2, count($result));
395+
self::assertSame($item1->timeSpent, $result[0]->timeSpent);
396+
397+
}
398+
372399
public function testAddWorklog(): void
373400
{
374401
$item = $this->createWorkflow(25, '2 hours');

0 commit comments

Comments
 (0)