Skip to content

Commit 864676e

Browse files
committed
Merge branch 'release/2.6.0'
2 parents c1e6df4 + 34ae096 commit 864676e

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6+
## [2.6.0] - 2023-02-09
7+
8+
### Added
9+
10+
- New `MultiPaginator` that allows a schema to offer multiple different pagination strategies.
11+
12+
### Fixed
13+
14+
- The JSON:API rule validators for the follow query parameter fields all errored if a non-array value was provided. This
15+
is now fixed:
16+
- `fields`
17+
- `page`
18+
- `filter`
19+
620
## [2.5.2] - 2023-01-25
721

822
### Fixed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
2828
"laravel-json-api/core": "^2.4",
29-
"laravel-json-api/eloquent": "^2.2.1",
29+
"laravel-json-api/eloquent": "^2.3",
3030
"laravel-json-api/encoder-neomerx": "^2.0.1",
3131
"laravel-json-api/exceptions": "^1.1.1",
3232
"laravel-json-api/spec": "^1.2",
33-
"laravel-json-api/validation": "^2.1.2",
33+
"laravel-json-api/validation": "^2.1.3",
3434
"laravel/framework": "^8.76|^9.0"
3535
},
3636
"require-dev": {

tests/dummy/app/JsonApi/V1/Posts/PostSchema.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
use LaravelJsonApi\Eloquent\Filters\Scope;
3333
use LaravelJsonApi\Eloquent\Filters\Where;
3434
use LaravelJsonApi\Eloquent\Filters\WhereIdIn;
35+
use LaravelJsonApi\Eloquent\Pagination\MultiPagination;
3536
use LaravelJsonApi\Eloquent\Pagination\PagePagination;
3637
use LaravelJsonApi\Eloquent\Schema;
3738
use LaravelJsonApi\Eloquent\SoftDeletes;
3839
use LaravelJsonApi\Eloquent\Sorting\SortCountable;
3940

4041
class PostSchema extends Schema
4142
{
42-
4343
use SoftDeletes;
4444

4545
/**
@@ -112,9 +112,15 @@ public function sortables(): iterable
112112
/**
113113
* @inheritDoc
114114
*/
115-
public function pagination(): PagePagination
115+
public function pagination(): MultiPagination
116116
{
117-
return PagePagination::make()->withoutNestedMeta();
117+
return new MultiPagination(
118+
PagePagination::make()->withoutNestedMeta(),
119+
PagePagination::make()
120+
->withoutNestedMeta()
121+
->withSimplePagination()
122+
->withPageKey('current-page')
123+
->withPerPageKey('per-page')
124+
);
118125
}
119-
120126
}

tests/dummy/tests/Api/V1/Posts/IndexTest.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use App\Models\Tag;
2424
use App\Models\User;
2525
use App\Tests\Api\V1\TestCase;
26+
use Faker\Generator;
2627
use Illuminate\Support\Arr;
2728
use Illuminate\Support\Facades\Date;
2829

@@ -79,7 +80,7 @@ public function testWithUser(): void
7980
$response->assertFetchedMany($expected);
8081
}
8182

82-
public function testPaginated(): void
83+
public function testPagePagination(): void
8384
{
8485
$posts = Post::factory()->count(5)->create();
8586

@@ -116,9 +117,52 @@ public function testPaginated(): void
116117
->page(['number' => 1, 'size' => 3])
117118
->get('/api/v1/posts');
118119

119-
$response->assertFetchedMany($expected)
120+
$response
121+
->assertFetchedMany($expected)
120122
->assertMeta($meta)
121-
->assertLinks($links);
123+
->assertExactLinks($links);
124+
}
125+
126+
public function testMultiPagination(): void
127+
{
128+
$posts = Post::factory()->count(6)->create([
129+
'created_at' => fn() => app(Generator::class)->dateTime(),
130+
])->sortByDesc('created_at')->values();
131+
132+
$expected = $this->identifiersFor('posts', $posts->skip(2)->take(2));
133+
134+
$meta = [
135+
'currentPage' => 2,
136+
'from' => 3,
137+
'perPage' => 2,
138+
'to' => 4,
139+
];
140+
141+
$links = [
142+
'first' => 'http://localhost/api/v1/posts?' . Arr::query([
143+
'page' => ['current-page' => 1, 'per-page' => 2],
144+
'sort' => '-createdAt',
145+
]),
146+
'next' => 'http://localhost/api/v1/posts?' . Arr::query([
147+
'page' => ['current-page' => 3, 'per-page' => 2],
148+
'sort' => '-createdAt',
149+
]),
150+
'prev' => 'http://localhost/api/v1/posts?' . Arr::query([
151+
'page' => ['current-page' => 1, 'per-page' => 2],
152+
'sort' => '-createdAt',
153+
]),
154+
];
155+
156+
$response = $this
157+
->jsonApi()
158+
->expects('posts')
159+
->page(['current-page' => 2, 'per-page' => 2])
160+
->get('/api/v1/posts');
161+
162+
$response
163+
->assertFetchedMany($expected)
164+
->assertMeta($meta)
165+
->assertExactLinks($links);
122166
}
123167

124168
public function testIncludeAuthor(): void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy