Skip to content

Commit 3fde242

Browse files
committed
Merge branch 'release/1.0.0-beta.3' into main
2 parents 0bbeef3 + 5471a9d commit 3fde242

File tree

19 files changed

+420
-29
lines changed

19 files changed

+420
-29
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
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+
## [1.0.0-beta.3] - 2021-04-26
7+
8+
### Added
9+
10+
- [#14](https://github.com/laravel-json-api/laravel/issues/14) Additional sort parameters can now be added to Eloquent
11+
schemas. Previously only sortable attributes were supported. These new classes are added to schemas in the
12+
`sortables()` method.
13+
- Eloquent schemas now support a default sort order via the `$defaultSort` property.
14+
- New generator command `jsonapi:sort-field` to create a custom sort field class.
15+
- [#74](https://github.com/laravel-json-api/laravel/issues/74) Developers can now add default include paths to the query
16+
request classes (e.g. `PostQuery` and `PostCollectionQuery`) via the `$defaultIncludePaths` property. These include
17+
paths are used if the client does not provide any include paths.
18+
619
## [1.0.0-beta.2] - 2021-04-20
720

821
### Added

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"require": {
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
28-
"laravel-json-api/core": "^1.0.0-beta.2",
29-
"laravel-json-api/eloquent": "^1.0.0-beta.2",
28+
"laravel-json-api/core": "^1.0.0-beta.3",
29+
"laravel-json-api/eloquent": "^1.0.0-beta.4",
3030
"laravel-json-api/encoder-neomerx": "^1.0.0-beta.1",
3131
"laravel-json-api/exceptions": "^1.0.0-beta.2",
3232
"laravel-json-api/spec": "^1.0.0-beta.1",
33-
"laravel-json-api/validation": "^1.0.0-beta.1",
33+
"laravel-json-api/validation": "^1.0.0-beta.2",
3434
"laravel/framework": "^8.0"
3535
},
3636
"require-dev": {

src/Console/MakeSortField.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace LaravelJsonApi\Laravel\Console;
21+
22+
use Illuminate\Console\GeneratorCommand as BaseGeneratorCommand;
23+
use Symfony\Component\Console\Input\InputOption;
24+
25+
class MakeSortField extends BaseGeneratorCommand
26+
{
27+
28+
use Concerns\ResolvesStub;
29+
30+
/**
31+
* @var string
32+
*/
33+
protected $name = 'jsonapi:sort-field';
34+
35+
/**
36+
* @var string
37+
*/
38+
protected $description = 'Create a new JSON:API sort field.';
39+
40+
/**
41+
* @var string
42+
*/
43+
protected $type = 'JSON:API sort field';
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
protected function getStub()
49+
{
50+
return $this->resolveStubPath('sort-field.stub');
51+
}
52+
53+
/**
54+
* @inheritDoc
55+
*/
56+
protected function getDefaultNamespace($rootNamespace)
57+
{
58+
$jsonApi = trim(config('jsonapi.namespace') ?: 'JsonApi', '\\');
59+
60+
return $rootNamespace . '\\' . $jsonApi . '\\' . 'Sorting';
61+
}
62+
63+
/**
64+
* Get the console command options.
65+
*
66+
* @return array
67+
*/
68+
protected function getOptions()
69+
{
70+
return [
71+
['force', null, InputOption::VALUE_NONE, 'Create the class even if the sort field already exists'],
72+
];
73+
}
74+
75+
}

src/Http/Controllers/Actions/FetchMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public function index(Route $route, StoreContract $store)
6161
$response = $this->searched($data, $request);
6262
}
6363

64-
return $response ?: new DataResponse($data);
64+
return $response ?: DataResponse::make($data)->withQueryParameters($request);
6565
}
6666
}

src/Http/Controllers/Actions/FetchOne.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public function show(Route $route, StoreContract $store)
6161
$response = $this->read($model, $request);
6262
}
6363

64-
return $response ?: new DataResponse($model);
64+
return $response ?: DataResponse::make($model)->withQueryParameters($request);
6565
}
6666
}

src/Http/Controllers/Actions/FetchRelated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public function showRelated(Route $route, StoreContract $store)
7676
$response = $this->{$hook}($model, $data, $request);
7777
}
7878

79-
return $response ?: new RelatedResponse(
79+
return $response ?: RelatedResponse::make(
8080
$model,
8181
$relation->name(),
8282
$data,
83-
);
83+
)->withQueryParameters($request);
8484
}
8585
}

src/Http/Controllers/Actions/FetchRelationship.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public function showRelationship(Route $route, StoreContract $store)
7676
$response = $this->{$hook}($model, $data, $request);
7777
}
7878

79-
return $response ?: new RelationshipResponse(
79+
return $response ?: RelationshipResponse::make(
8080
$model,
8181
$relation->name(),
8282
$data
83-
);
83+
)->withQueryParameters($request);
8484
}
8585
}

src/Http/Controllers/Actions/Store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ public function store(Route $route, StoreContract $store)
7171
$response = $this->saved($model, $request, $query);
7272
}
7373

74-
return $response ?: new DataResponse($model);
74+
return $response ?: DataResponse::make($model)->withQueryParameters($query);
7575
}
7676
}

src/Http/Controllers/Actions/Update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ public function update(Route $route, StoreContract $store)
7373
$response = $this->saved($model, $request, $query);
7474
}
7575

76-
return $response ?: new DataResponse($model);
76+
return $response ?: DataResponse::make($model)->withQueryParameters($query);
7777
}
7878
}

src/Http/Controllers/Actions/UpdateRelationship.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public function updateRelationship(Route $route, StoreContract $store)
8181
$response = $this->{$hook}($model, $result, $request, $query);
8282
}
8383

84-
return $response ?: new RelationshipResponse(
84+
return $response ?: RelationshipResponse::make(
8585
$model,
8686
$fieldName,
8787
$result
88-
);
88+
)->withQueryParameters($query);
8989
}
9090
}

0 commit comments

Comments
 (0)