Skip to content

Commit 13148c8

Browse files
committed
feat(stories): Add published_at_gt and other date related query parameters (#64)
1 parent 006cdab commit 13148c8

16 files changed

+656
-11
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,38 @@ new OrFilter(
309309
);
310310
```
311311

312+
#### Filtering by native date fields
313+
314+
The Storyblok API allows filtering by published or updated dates.
315+
Those fields could not be filtered by `gt_date` or `lt_date` operations and have dedicated parameters in the request.
316+
317+
Supported date parameters are:
318+
* `published_at_gt`
319+
* `published_at_lt`
320+
* `first_published_at_gt`
321+
* `first_published_at_lt`
322+
* `updated_at_gt`
323+
* `updated_at_lt`
324+
325+
Ensure that the dates used have to be in UTC timezone.
326+
327+
```php
328+
use Storyblok\Api\StoriesApi;
329+
use Storyblok\Api\StoryblokClient;
330+
use Storyblok\Api\Domain\Value\QueryParameter\PublishedAtGt;
331+
use Storyblok\Api\Request\StoriesRequest;
332+
333+
$dateTime = new \DateTimeImmutable('1969-12-28 12:12:12.425', new \DateTimeZone('UTC'));
334+
335+
$client = new StoryblokClient(/* ... */);
336+
337+
$storiesApi = new StoriesApi($client);
338+
$response = $storiesApi->all(new StoriesRequest(
339+
language: 'de',
340+
publishedAtGt: new PublishedAtGt($dateTime)
341+
));
342+
```
343+
312344
### Get all available stories by Content Type (`string`)
313345

314346
```php
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class FirstPublishedAtGt
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'first_published_at_gt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format('Y-m-d\TH:i:s.v\Z');
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class FirstPublishedAtLt
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'first_published_at_lt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format('Y-m-d\TH:i:s.v\Z');
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class PublishedAtGt
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'published_at_gt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format('Y-m-d\TH:i:s.v\Z');
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class PublishedAtLt
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'published_at_lt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format('Y-m-d\TH:i:s.v\Z');
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class UpdatedAtGt
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'updated_at_gt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format('Y-m-d\TH:i:s.v\Z');
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class UpdatedAtLt
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'updated_at_lt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format('Y-m-d\TH:i:s.v\Z');
34+
}
35+
}

src/Request/StoriesRequest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
use Storyblok\Api\Domain\Value\Field\FieldCollection;
2121
use Storyblok\Api\Domain\Value\Filter\FilterCollection;
2222
use Storyblok\Api\Domain\Value\IdCollection;
23+
use Storyblok\Api\Domain\Value\QueryParameter\FirstPublishedAtGt;
24+
use Storyblok\Api\Domain\Value\QueryParameter\FirstPublishedAtLt;
25+
use Storyblok\Api\Domain\Value\QueryParameter\PublishedAtGt;
26+
use Storyblok\Api\Domain\Value\QueryParameter\PublishedAtLt;
27+
use Storyblok\Api\Domain\Value\QueryParameter\UpdatedAtGt;
28+
use Storyblok\Api\Domain\Value\QueryParameter\UpdatedAtLt;
2329
use Storyblok\Api\Domain\Value\Resolver\RelationCollection;
2430
use Storyblok\Api\Domain\Value\Resolver\ResolveLinks;
2531
use Storyblok\Api\Domain\Value\Slug\Slug;
@@ -49,6 +55,12 @@ public function __construct(
4955
public ResolveLinks $resolveLinks = new ResolveLinks(),
5056
public SlugCollection $excludeSlugs = new SlugCollection(),
5157
public ?Slug $startsWith = null,
58+
public ?PublishedAtGt $publishedAtGt = null,
59+
public ?PublishedAtLt $publishedAtLt = null,
60+
public ?FirstPublishedAtGt $firstPublishedAtGt = null,
61+
public ?FirstPublishedAtLt $firstPublishedAtLt = null,
62+
public ?UpdatedAtGt $updatedAtGt = null,
63+
public ?UpdatedAtLt $updatedAtLt = null,
5264
) {
5365
Assert::stringNotEmpty($language);
5466
Assert::lessThanEq($this->pagination->perPage, self::MAX_PER_PAGE);
@@ -71,6 +83,12 @@ public function __construct(
7183
* version?: string,
7284
* excluding_slugs?: string,
7385
* starts_with?: string,
86+
* published_at_gt?: string,
87+
* published_at_lt?: string,
88+
* first_published_at_gt?: string,
89+
* first_published_at_lt?: string,
90+
* updated_at_gt?: string,
91+
* updated_at_lt?: string,
7492
* }
7593
*/
7694
public function toArray(): array
@@ -126,6 +144,30 @@ public function toArray(): array
126144
$array['starts_with'] = $this->startsWith->value;
127145
}
128146

147+
if (null !== $this->publishedAtGt) {
148+
$array['published_at_gt'] = $this->publishedAtGt->toString();
149+
}
150+
151+
if (null !== $this->publishedAtLt) {
152+
$array['published_at_lt'] = $this->publishedAtLt->toString();
153+
}
154+
155+
if (null !== $this->firstPublishedAtGt) {
156+
$array['first_published_at_gt'] = $this->firstPublishedAtGt->toString();
157+
}
158+
159+
if (null !== $this->firstPublishedAtLt) {
160+
$array['first_published_at_lt'] = $this->firstPublishedAtLt->toString();
161+
}
162+
163+
if (null !== $this->updatedAtGt) {
164+
$array['updated_at_gt'] = $this->updatedAtGt->toString();
165+
}
166+
167+
if (null !== $this->updatedAtLt) {
168+
$array['updated_at_lt'] = $this->updatedAtLt->toString();
169+
}
170+
129171
return $array;
130172
}
131173
}

tests/Unit/Domain/Type/AssetTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,6 @@ public function orientation(Orientation $expected, int $width, int $height): voi
285285
self::assertTrue($expected->equals((new Asset($response))->orientation));
286286
}
287287

288-
#[Test]
289-
public function orientationWithNoImage(): void
290-
{
291-
$faker = self::faker();
292-
$response = $faker->storyAssetResponse([
293-
'filename' => $faker->url(),
294-
]);
295-
296-
self::assertTrue(Orientation::Unknown->equals((new Asset($response))->orientation));
297-
}
298-
299288
/**
300289
* @return iterable<string, array{0: Orientation, 1: int, 2: int}>
301290
*/
@@ -309,6 +298,17 @@ public static function orientationProvider(): iterable
309298
yield 'portrait' => [Orientation::Portrait, 1080, 1920];
310299
}
311300

301+
#[Test]
302+
public function orientationWithNoImage(): void
303+
{
304+
$faker = self::faker();
305+
$response = $faker->storyAssetResponse([
306+
'filename' => $faker->url(),
307+
]);
308+
309+
self::assertTrue(Orientation::Unknown->equals((new Asset($response))->orientation));
310+
}
311+
312312
#[Test]
313313
public function isExternalUrl(): void
314314
{

0 commit comments

Comments
 (0)