Skip to content

Commit c3e49b7

Browse files
committed
[internal-api-client] Use specific elastic mapping for search endpoints
1 parent 5a3d861 commit c3e49b7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/Client.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public function searchJobs(
354354
$request = new Request('GET', 'search/jobs?' . http_build_query($query));
355355
$response = $this->sendRequest($request);
356356

357-
return $this->mapJobsFromResponse($response);
357+
return $this->mapJobsFromSearchResponse($response);
358358
}
359359

360360
/**
@@ -418,7 +418,16 @@ public function searchJobsGrouped(
418418
$request = new Request('GET', 'search/grouped-jobs?' . http_build_query($query));
419419
$response = $this->sendRequest($request);
420420

421-
return $this->mapJobsFromResponse($response);
421+
return $this->mapJobsFromSearchResponse($response);
422+
}
423+
424+
/** @return JobInterface[] */
425+
private function mapJobsFromSearchResponse(array $responseBody): array
426+
{
427+
return array_map(
428+
fn(array $jobData): JobInterface => $this->existingJobFactory->loadFromElasticJobData($jobData),
429+
$responseBody,
430+
);
422431
}
423432

424433
/**

src/ExistingJobFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Keboola\JobQueueInternalClient;
66

7+
use Keboola\JobQueueInternalClient\JobFactory\ElasticJobDefinition;
78
use Keboola\JobQueueInternalClient\JobFactory\FullJobDefinition;
89
use Keboola\JobQueueInternalClient\JobFactory\Job;
910
use Keboola\JobQueueInternalClient\JobFactory\JobInterface;
@@ -24,4 +25,11 @@ public function loadFromExistingJobData(array $data): JobInterface
2425

2526
return new Job($this->objectEncryptor, $this->storageClientFactory, $data);
2627
}
28+
29+
public function loadFromElasticJobData(array $data): JobInterface
30+
{
31+
$data = $this->validateJobData($data, ElasticJobDefinition::class);
32+
33+
return new Job($this->objectEncryptor, $this->storageClientFactory, $data);
34+
}
2735
}

tests/ClientSearchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ private function createClient(array &$requests, array $responses): Client
311311
$handlerStack->push(Middleware::history($requests));
312312

313313
$existingJobFactory = $this->createMock(ExistingJobFactory::class);
314-
$existingJobFactory->method('loadFromExistingJobData')
314+
$existingJobFactory->method('loadFromElasticJobData')
315315
->willReturnCallback(function (array $data) {
316316
$job = $this->createMock(Job::class);
317317
$job->method('getId')->willReturn((string) $data['id']);

0 commit comments

Comments
 (0)