Skip to content

Commit 8e62cb1

Browse files
authored
Merge pull request hkulekci#28 from mbukovy/patch-1
Support uuid for Points
2 parents e8e361e + 87245a8 commit 8e62cb1

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/Endpoints/Collections/Points.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function ids(array $ids, $withPayload = false, $withVector = true, array
111111
/**
112112
* @throws InvalidArgumentException
113113
*/
114-
public function id(int $id, array $queryParams = []): Response
114+
public function id(int|string $id, array $queryParams = []): Response
115115
{
116116
return $this->client->execute(
117117
$this->createRequest(
@@ -190,4 +190,4 @@ public function recommend(RecommendRequest $recommendParams): Response
190190
)
191191
);
192192
}
193-
}
193+
}

src/Models/PointStruct.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class PointStruct
1616
use ProtectedPropertyAccessor;
1717

1818
// TODO: we need a solution for point with uuid
19-
protected int $id;
19+
protected int|string $id;
2020
protected ?array $payload = null;
2121
protected VectorStruct $vector;
2222

23-
public function __construct(int $id, VectorStruct $vector, array $payload = null)
23+
public function __construct(int|string $id, VectorStruct $vector, array $payload = null)
2424
{
2525
$this->id = $id;
2626
$this->vector = $vector;
@@ -58,7 +58,7 @@ public function toArray(): array
5858
/**
5959
* @return int
6060
*/
61-
public function getId(): int
61+
public function getId(): int|string
6262
{
6363
return $this->id;
6464
}
@@ -78,4 +78,4 @@ public function getVector(): VectorStruct
7878
{
7979
return $this->vector;
8080
}
81-
}
81+
}

tests/Unit/Models/PointStructTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ public function testPointStruct(): void
2626
);
2727
}
2828

29+
public function testPointStructWithUUid(): void
30+
{
31+
$point = new PointStruct('550e8400-e29b-41d4-a716-446655440000', new VectorStruct([1, 2, 3]));
32+
33+
$this->assertEquals(
34+
[
35+
'id' => '550e8400-e29b-41d4-a716-446655440000',
36+
'vector' => [1, 2, 3]
37+
],
38+
$point->toArray()
39+
);
40+
}
41+
2942
public function testPointStructWithArray(): void
3043
{
3144
$points = PointStruct::createFromArray([

tests/Unit/Models/PointsStructTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ public function testPointsStruct(): void
3434
);
3535
}
3636

37+
public function testPointsStructWithUUid(): void
38+
{
39+
$points = new PointsStruct();
40+
$points->addPoint(
41+
new PointStruct(
42+
'550e8400-e29b-41d4-a716-446655440000',
43+
new VectorStruct([1, 2, 3])
44+
)
45+
);
46+
47+
$this->assertEquals(
48+
[
49+
[
50+
'id' => '550e8400-e29b-41d4-a716-446655440000',
51+
'vector' => [1, 2, 3]
52+
]
53+
],
54+
$points->toArray()
55+
);
56+
}
57+
3758
public function testPointsStructWithArray(): void
3859
{
3960
$points = PointsStruct::createFromArray([
@@ -64,7 +85,7 @@ public function testPointsStructWithNamedVectors(): void
6485
],
6586
],
6687
[
67-
'id' => 1,
88+
'id' => '550e8400-e29b-41d4-a716-446655440000',
6889
'vector' => [
6990
'image' => [3, 4, 5]
7091
],
@@ -80,7 +101,7 @@ public function testPointsStructWithNamedVectors(): void
80101
],
81102
],
82103
[
83-
'id' => 1,
104+
'id' => '550e8400-e29b-41d4-a716-446655440000',
84105
'vector' => [
85106
'image' => [3, 4, 5]
86107
],

0 commit comments

Comments
 (0)