Skip to content

Commit 48b1415

Browse files
authored
feat(stories): Add starts_with option (#49)
1 parent 6393206 commit 48b1415

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Request/StoriesRequest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Storyblok\Api\Domain\Value\IdCollection;
2323
use Storyblok\Api\Domain\Value\Resolver\RelationCollection;
2424
use Storyblok\Api\Domain\Value\Resolver\ResolveLinks;
25+
use Storyblok\Api\Domain\Value\Slug\Slug;
2526
use Storyblok\Api\Domain\Value\Slug\SlugCollection;
2627
use Storyblok\Api\Domain\Value\Tag\TagCollection;
2728
use Webmozart\Assert\Assert;
@@ -47,6 +48,7 @@ public function __construct(
4748
public ?string $searchTerm = null,
4849
public ResolveLinks $resolveLinks = new ResolveLinks(),
4950
public SlugCollection $excludeSlugs = new SlugCollection(),
51+
public ?Slug $startsWith = null,
5052
) {
5153
Assert::stringNotEmpty($language);
5254
Assert::lessThanEq($this->pagination->perPage, self::MAX_PER_PAGE);
@@ -68,6 +70,7 @@ public function __construct(
6870
* search_term?: string,
6971
* version?: string,
7072
* excluding_slugs?: string,
73+
* starts_with?: string,
7174
* }
7275
*/
7376
public function toArray(): array
@@ -119,6 +122,10 @@ public function toArray(): array
119122
$array['excluding_slugs'] = $this->excludeSlugs->toString();
120123
}
121124

125+
if (null !== $this->startsWith) {
126+
$array['starts_with'] = $this->startsWith->value;
127+
}
128+
122129
return $array;
123130
}
124131
}

tests/Unit/Request/StoriesRequestTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,19 @@ public function toArrayExcludeSlugs(): void
206206
'excluding_slugs' => 'path/*,another-path/*',
207207
], $request->toArray());
208208
}
209+
210+
#[Test]
211+
public function toArrayStartsWith(): void
212+
{
213+
$request = new StoriesRequest(
214+
startsWith: new Slug('my/path'),
215+
);
216+
217+
self::assertSame([
218+
'language' => 'default',
219+
'page' => 1,
220+
'per_page' => 25,
221+
'starts_with' => 'my/path',
222+
], $request->toArray());
223+
}
209224
}

0 commit comments

Comments
 (0)