Skip to content

Commit cf7c909

Browse files
committed
Added parameter "first" to the job list request.
1 parent e5f9690 commit cf7c909

File tree

8 files changed

+65
-32
lines changed

8 files changed

+65
-32
lines changed

api/openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ paths:
111111
schema:
112112
type: number
113113
default: 10
114+
- name: first
115+
in: query
116+
description: The first job to return.
117+
schema:
118+
type: number
119+
default: 0
114120
responses:
115121
200:
116122
description: The list of matched export jobs.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"bluepsyduck/mapper-manager": "^1.2",
2121
"doctrine/orm": "^2.6",
2222
"factorio-item-browser/common": "^1.3",
23-
"factorio-item-browser/combination-api-client": "^1.0",
23+
"factorio-item-browser/combination-api-client": "dev-master as 1.1",
2424
"laminas/laminas-config-aggregator": "^1.4",
2525
"laminas/laminas-diactoros": "^2.5",
2626
"laminas/laminas-log": "^2.13",

composer.lock

Lines changed: 31 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Helper/QueuePositionHelper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public function injectQueuePosition(Job $job): void
4949
private function fetchQueuePositions(): array
5050
{
5151
$positions = [];
52-
$jobs = $this->jobRepository->findAll(null, JobStatus::QUEUED, ListOrder::PRIORITY, self::MAX_QUEUE_POSITION);
52+
$jobs = $this->jobRepository->findAll(
53+
null,
54+
JobStatus::QUEUED,
55+
ListOrder::PRIORITY,
56+
self::MAX_QUEUE_POSITION,
57+
0,
58+
);
5359
foreach ($jobs as $index => $job) {
5460
$positions[$job->getId()->toString()] = $index + 1;
5561
}

src/Repository/JobRepository.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function findById(UuidInterface $jobId): ?Job
4545
$query->setParameter('jobId', $jobId, UuidBinaryType::NAME);
4646
try {
4747
return $query->getOneOrNullResult();
48-
} catch (NonUniqueResultException $e) {
48+
} catch (NonUniqueResultException) {
4949
// Will never happen: We are searching for the primary key.
5050
return null;
5151
}
@@ -57,14 +57,16 @@ public function findById(UuidInterface $jobId): ?Job
5757
* @param string $status
5858
* @param string $order
5959
* @param int $limit
60+
* @param int $first
6061
* @return array<Job>
6162
*/
62-
public function findAll(?UuidInterface $combinationId, string $status, string $order, int $limit): array
63+
public function findAll(?UuidInterface $combinationId, string $status, string $order, int $limit, int $first): array
6364
{
6465
$queryBuilder = $this->entityManager->createQueryBuilder();
6566
$queryBuilder->select('j')
6667
->from(Job::class, 'j')
67-
->setMaxResults($limit);
68+
->setMaxResults($limit)
69+
->setFirstResult($first);
6870

6971
if ($combinationId !== null) {
7072
$queryBuilder->andWhere('j.combination = :combinationId')

src/Service/JobService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getJobFromRequestValue(string $jobId): Job
4545
{
4646
try {
4747
$id = Uuid::fromString($jobId);
48-
} catch (Exception $e) {
48+
} catch (Exception) {
4949
throw new InvalidJobIdException($jobId);
5050
}
5151

@@ -65,15 +65,16 @@ public function getJobsFromQueryParams(array $queryParams): array
6565
{
6666
try {
6767
$combinationId = Uuid::fromString($queryParams[ParameterName::COMBINATION_ID] ?? '');
68-
} catch (Exception $e) {
68+
} catch (Exception) {
6969
$combinationId = null;
7070
}
7171

7272
return $this->jobRepository->findAll(
7373
$combinationId,
7474
$queryParams[ParameterName::STATUS] ?? '',
7575
$queryParams[ParameterName::ORDER] ?? '',
76-
(int) ($queryParams[ParameterName::LIMIT] ?? 10)
76+
(int) ($queryParams[ParameterName::LIMIT] ?? 10),
77+
(int) ($queryParams[ParameterName::FIRST] ?? 0),
7778
);
7879
}
7980

test/src/Repository/JobRepositoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function testFindAll(
157157
array $expectedOrders
158158
): void {
159159
$limit = 42;
160+
$first = 21;
160161

161162
$jobs = [
162163
$this->createMock(Job::class),
@@ -189,6 +190,10 @@ public function testFindAll(
189190
->method('setMaxResults')
190191
->with($this->identicalTo($limit))
191192
->willReturnSelf();
193+
$queryBuilder->expects($this->once())
194+
->method('setFirstResult')
195+
->with($this->identicalTo($first))
196+
->willReturnSelf();
192197
$queryBuilder->expects($this->exactly(count($expectedOrders)))
193198
->method('addOrderBy')
194199
->withConsecutive(...$expectedOrders)
@@ -203,7 +208,7 @@ public function testFindAll(
203208
->willReturn($queryBuilder);
204209

205210
$instance = new JobRepository($entityManager);
206-
$result = $instance->findAll($combinationId, $status, $order, $limit);
211+
$result = $instance->findAll($combinationId, $status, $order, $limit, $first);
207212

208213
$this->assertSame($jobs, $result);
209214
}

test/src/Service/JobServiceTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function testGetJobsFromQueryParams(): void
110110
'status' => 'abc',
111111
'order' => 'def',
112112
'limit' => '42',
113+
'first' => '21',
113114
];
114115
$jobs = [
115116
$this->createMock(Job::class),
@@ -122,7 +123,8 @@ public function testGetJobsFromQueryParams(): void
122123
$this->equalTo(Uuid::fromString('2f4a45fa-a509-a9d1-aae6-ffcf984a7a76')),
123124
$this->identicalTo('abc'),
124125
$this->identicalTo('def'),
125-
$this->identicalTo(42)
126+
$this->identicalTo(42),
127+
$this->identicalTo(21),
126128
)
127129
->willReturn($jobs);
128130

@@ -145,7 +147,8 @@ public function testGetJobsFromQueryParamsWithoutValues(): void
145147
$this->isNull(),
146148
$this->identicalTo(''),
147149
$this->identicalTo(''),
148-
$this->identicalTo(10)
150+
$this->identicalTo(10),
151+
$this->identicalTo(0),
149152
)
150153
->willReturn($jobs);
151154

0 commit comments

Comments
 (0)