Skip to content

Commit c8462ad

Browse files
author
Tomáš Lipenský
committed
feat: added endpoint to find workload by ID
1 parent fb62c0e commit c8462ad

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+
* @return array<Worklog>
433+
*/
434+
public function getWorklogsByIds(array $ids): array
435+
{
436+
$ret = $this->client->exec("/worklog/list", json_encode(["ids" => $ids]), "POST");
437+
438+
$this->logger->debug("getWorklogsByIds res=$ret\n");
439+
440+
$worklogsResponse = json_decode($ret, false, 512, JSON_THROW_ON_ERROR);
441+
442+
$worklogs = array_map(function ($worklog) {
443+
return $this->jsonMapper->map($worklog, new Worklog());
444+
}, $worklogsResponse);
445+
446+
return $worklogs;
447+
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)