Skip to content

Commit 9eafd40

Browse files
authored
Merge pull request #121 from apisearch-io/fix/changed-repository-reference-to-simple-model
Changed repository_reference to simple objects
2 parents 4497afe + 61ccc90 commit 9eafd40

12 files changed

+61
-32
lines changed

App/AppRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function checkIndex(IndexUUID $indexUUID): bool;
107107
*
108108
* @param IndexUUID $indexUUID
109109
* @param Config $config
110-
* @param bool $forceReindex
110+
* @param bool $forceReindex
111111
*
112112
* @throws ResourceNotAvailableException
113113
*/

App/DiskAppRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
120120
*
121121
* @param IndexUUID $indexUUID
122122
* @param Config $config
123-
* @param bool $forceReindex
123+
* @param bool $forceReindex
124124
*
125125
* @throws ResourceNotAvailableException
126126
*/

App/HttpAppRepository.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
268268
*
269269
* @param IndexUUID $indexUUID
270270
* @param Config $config
271-
* @param bool $forceReindex
271+
* @param bool $forceReindex
272272
*
273273
* @throws ResourceNotAvailableException
274274
*/
@@ -287,7 +287,7 @@ public function configureIndex(
287287
),
288288
'post',
289289
[
290-
'force_reindex' => $forceReindex
290+
'force_reindex' => $forceReindex,
291291
],
292292
$config->toArray(),
293293
Http::getApisearchHeaders($this)

App/InMemoryAppRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
141141
*
142142
* @param IndexUUID $indexUUID
143143
* @param Config $config
144-
* @param bool $forceReindex
144+
* @param bool $forceReindex
145145
*
146146
* @throws ResourceNotAvailableException
147147
*/

App/MockAppRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
134134
*
135135
* @param IndexUUID $indexUUID
136136
* @param Config $config
137-
* @param bool $forceReindex
137+
* @param bool $forceReindex
138138
*
139139
* @throws ResourceNotAvailableException
140140
*/

Model/Item.php

+33-12
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ class Item implements HttpTransportable, UUIDReference
101101
private $score;
102102

103103
/**
104-
* @var RepositoryReference
104+
* @var AppUUID|null
105105
*/
106-
private $repositoryReference;
106+
private $appUUID;
107+
108+
/**
109+
* @var IndexUUID|null
110+
*/
111+
private $indexUUID;
107112

108113
/**
109114
* Item constructor.
@@ -496,19 +501,28 @@ public function setScore(float $score)
496501
}
497502

498503
/**
499-
* @return RepositoryReference|null
504+
* @param RepositoryReference $repositoryReference
500505
*/
501-
public function getRepositoryReference():? RepositoryReference
506+
public function setRepositoryReference(RepositoryReference $repositoryReference)
502507
{
503-
return $this->repositoryReference;
508+
$this->appUUID = $repositoryReference->getAppUUID();
509+
$this->indexUUID = $repositoryReference->getIndexUUID();
504510
}
505511

506512
/**
507-
* @param RepositoryReference $repositoryReference
513+
* @return AppUUID|null
508514
*/
509-
public function setRepositoryReference(RepositoryReference $repositoryReference)
515+
public function getAppUUID(): ?AppUUID
510516
{
511-
$this->repositoryReference = $repositoryReference;
517+
return $this->appUUID;
518+
}
519+
520+
/**
521+
* @return IndexUUID|null
522+
*/
523+
public function getIndexUUID(): ?IndexUUID
524+
{
525+
return $this->indexUUID;
512526
}
513527

514528
/**
@@ -532,8 +546,11 @@ public function toArray(): array
532546
'highlights' => $this->highlights,
533547
'is_promoted' => !$this->promoted ? null : true,
534548
'score' => $this->score,
535-
'repository_reference' => $this->repositoryReference instanceof RepositoryReference
536-
? $this->repositoryReference->compose()
549+
'app_uuid' => $this->appUUID instanceof AppUUID
550+
? $this->appUUID->toArray()
551+
: null,
552+
'index_uuid' => $this->indexUUID instanceof IndexUUID
553+
? $this->indexUUID->toArray()
537554
: null,
538555
], function ($element) {
539556
return
@@ -602,8 +619,12 @@ public static function createFromArray(array $array): self
602619
$item->setScore((float) $array['score']);
603620
}
604621

605-
if (isset($array['repository_reference']) && !is_null($array['repository_reference'])) {
606-
$item->setRepositoryReference(RepositoryReference::createFromComposed($array['repository_reference']));
622+
if (isset($array['app_uuid']) && !is_null($array['app_uuid'])) {
623+
$item->appUUID = AppUUID::createFromArray($array['app_uuid']);
624+
}
625+
626+
if (isset($array['index_uuid']) && !is_null($array['index_uuid'])) {
627+
$item->indexUUID = IndexUUID::createFromArray($array['index_uuid']);
607628
}
608629

609630
return $item;

Repository/HttpRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function updateItems(
132132
}
133133

134134
/**
135-
* Delete items by query
135+
* Delete items by query.
136136
*
137137
* @param Query $query
138138
*/

Repository/InMemoryRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function updateItems(
9898
}
9999

100100
/**
101-
* Delete items by query
101+
* Delete items by query.
102102
*
103103
* @param Query $query
104104
*/

Repository/MockRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function updateItems(
7373
}
7474

7575
/**
76-
* Delete items by query
76+
* Delete items by query.
7777
*
7878
* @param Query $query
7979
*/

Repository/Repository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ abstract public function updateItems(
201201
);
202202

203203
/**
204-
* Delete items by query
204+
* Delete items by query.
205205
*
206206
* @param Query $query
207207
*/

Repository/TransformableRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function updateItems(
185185
}
186186

187187
/**
188-
* Delete items by query
188+
* Delete items by query.
189189
*
190190
* @param Query $query
191191
*/

Tests/Model/ItemTest.php

+17-9
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public function testScore()
431431
}
432432

433433
/**
434-
* Test index and app UUID
434+
* Test index and app UUID.
435435
*/
436436
public function testIndexAndAppUUID()
437437
{
@@ -440,22 +440,30 @@ public function testIndexAndAppUUID()
440440
$repositoryReference = RepositoryReference::create($appUUID, $indexUUID);
441441

442442
$item = Item::create(ItemUUID::createByComposedUUID('1~item'));
443-
$this->assertNull($item->getRepositoryReference());
443+
$this->assertNull($item->getAppUUID());
444+
$this->assertNull($item->getIndexUUID());
444445
$item = Item::createFromArray($item->toArray());
445-
$this->assertNull($item->getRepositoryReference());
446-
447-
446+
$this->assertNull($item->getAppUUID());
447+
$this->assertNull($item->getIndexUUID());
448448

449449
$item = Item::create(ItemUUID::createByComposedUUID('1~item'));
450450
$item->setRepositoryReference($repositoryReference);
451451
$this->assertEquals(
452-
$repositoryReference,
453-
$item->getRepositoryReference()
452+
$repositoryReference->getIndexUUID(),
453+
$item->getIndexUUID()
454+
);
455+
$this->assertEquals(
456+
$repositoryReference->getAppUUID(),
457+
$item->getAppUUID()
454458
);
455459
$item = Item::createFromArray($item->toArray());
456460
$this->assertEquals(
457-
$repositoryReference,
458-
$item->getRepositoryReference()
461+
$repositoryReference->getAppUUID(),
462+
$item->getAppUUID()
463+
);
464+
$this->assertEquals(
465+
$repositoryReference->getAppUUID(),
466+
$item->getAppUUID()
459467
);
460468
}
461469
}

0 commit comments

Comments
 (0)