Skip to content

Commit 6c99809

Browse files
authored
Add StoriesRequest::$searchTerm (#15)
1 parent 4800e62 commit 6c99809

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Request/StoriesRequest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Storyblok\Api\Request;
1515

16+
use OskarStark\Value\TrimmedNonEmptyString;
1617
use Storyblok\Api\Domain\Value\Dto\Pagination;
1718
use Storyblok\Api\Domain\Value\Dto\SortBy;
1819
use Storyblok\Api\Domain\Value\Dto\Version;
@@ -41,6 +42,7 @@ public function __construct(
4142
public ?IdCollection $excludeIds = null,
4243
public ?RelationCollection $withRelations = null,
4344
public ?Version $version = null,
45+
public ?string $searchTerm = null,
4446
) {
4547
Assert::stringNotEmpty($language);
4648
Assert::lessThanEq($this->pagination->perPage, self::MAX_PER_PAGE);
@@ -56,6 +58,7 @@ public function __construct(
5658
* with_tag?: string,
5759
* excluding_fields?: string,
5860
* excluding_ids?: string,
61+
* search_term?: string,
5962
* version?: string,
6063
* }
6164
*/
@@ -91,6 +94,10 @@ public function toArray(): array
9194
$array['resolve_relations'] = $this->withRelations->toString();
9295
}
9396

97+
if (null !== $this->searchTerm) {
98+
$array['search_term'] = $this->searchTerm;
99+
}
100+
94101
if (null !== $this->version) {
95102
$array['version'] = $this->version->value;
96103
}

tests/Unit/Request/StoriesRequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,21 @@ public function toArrayWithVersion(): void
185185
'version' => $version->value,
186186
], $request->toArray());
187187
}
188+
189+
/**
190+
* @test
191+
*/
192+
public function toArrayWithSearchTerm(): void
193+
{
194+
$request = new StoriesRequest(
195+
searchTerm: $searchTerm = self::faker()->word(),
196+
);
197+
198+
self::assertSame([
199+
'language' => 'default',
200+
'page' => 1,
201+
'per_page' => 25,
202+
'search_term' => $searchTerm,
203+
], $request->toArray());
204+
}
188205
}

0 commit comments

Comments
 (0)