Skip to content

WIP: Implement related relationship access #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions src/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ class ArticleController extends \Phramework\Examples\JSONAPI\Controller
* @param string $method Request method
* @param array $headers Request headers
*/
public static function GET(\stdClass $params, string $method, array $headers)
{
public static function GET(
\stdClass $params,
string $method,
array $headers
) {
static::handleGET(
$params,
Article::class,
Expand All @@ -52,8 +55,12 @@ public static function GET(\stdClass $params, string $method, array $headers)
* @param array $headers Request headers
* @param string $id Resource id
*/
public static function GETById(\stdClass $params, string $method, array $headers, string $id)
{
public static function GETById(
\stdClass $params,
string $method,
array $headers,
string $id
) {
static::handleGETById(
$params,
$id,
Expand All @@ -69,8 +76,11 @@ public static function GETById(\stdClass $params, string $method, array $headers
* @param string $method Request method
* @param array $headers Request headers
*/
public static function POST(\stdClass $params, string $method, array $headers)
{
public static function POST(
\stdClass $params,
string $method,
array $headers
) {
$now = time();

static::handlePOST(
Expand Down Expand Up @@ -204,4 +214,32 @@ public static function byIdRelationships(
[]
);
}

/**
* Access resource's relationship resources
* `/article/{id}/{relationship}/` handler
* @param \stdClass $params
* @param string $method
* @param array $headers
* @param string $id
* @param string $relationship
*/
public static function byIdRelationshipsRelated(
\stdClass $params,
string $method,
array $headers,
string $id,
string $relationship
) {
static::handleByIdRelationshipsRelated(
$params,
$method,
$headers,
$id,
$relationship,
Article::class,
[\Phramework\Phramework::METHOD_GET],
[]
);
}
}
18 changes: 18 additions & 0 deletions src/Controllers/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public function getRouting(): array
'byIdRelationships',
Phramework::METHOD_ANY
],
[
'article/{id}/{relationship}',
ArticleController::class,
'byIdRelationshipsRelated',
Phramework::METHOD_ANY
],

[
'tag/',
Expand All @@ -71,6 +77,12 @@ public function getRouting(): array
'byIdRelationships',
Phramework::METHOD_ANY
],
[
'tag/{id}/{relationship}',
TagController::class,
'byIdRelationshipsRelated',
Phramework::METHOD_ANY
],

[
'user/',
Expand All @@ -90,6 +102,12 @@ public function getRouting(): array
'byIdRelationships',
Phramework::METHOD_ANY
],
[
'user/{id}/{relationship}',
UserController::class,
'byIdRelationshipsRelated',
Phramework::METHOD_ANY
],
];
}
}
49 changes: 42 additions & 7 deletions src/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class TagController extends \Phramework\Examples\JSONAPI\Controller
* @param string $method Request method
* @param array $headers Request headers
*/
public static function GET($params, $method, $headers)
{
public static function GET(
\stdClass $params,
string $method,
array $headers
) {
static::handleGET(
$params,
Tag::class,
Expand All @@ -50,8 +53,12 @@ public static function GET($params, $method, $headers)
* @param array $headers Request headers
* @param string $id Resource id
*/
public static function GETById($params, $method, $headers, string $id)
{
public static function GETById(
\stdClass $params,
string $method,
array $headers,
string $id
) {
static::handleGETById(
$params,
$id,
Expand All @@ -70,9 +77,9 @@ public static function GETById($params, $method, $headers, string $id)
* @param string $relationship Relationship
*/
public static function byIdRelationships(
$params,
$method,
$headers,
\stdClass $params,
string $method,
array $headers,
string $id,
string $relationship
) {
Expand All @@ -88,4 +95,32 @@ public static function byIdRelationships(
[]
);
}

/**
* Access resource's relationship resources
* `/tag/{id}/{relationship}/` handler
* @param \stdClass $params
* @param string $method
* @param array $headers
* @param string $id
* @param string $relationship
*/
public static function byIdRelationshipsRelated(
\stdClass $params,
string $method,
array $headers,
string $id,
string $relationship
) {
static::handleByIdRelationshipsRelated(
$params,
$method,
$headers,
$id,
$relationship,
Tag::class,
[\Phramework\Phramework::METHOD_GET],
[]
);
}
}
49 changes: 42 additions & 7 deletions src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class UserController extends \Phramework\Examples\JSONAPI\Controller
* @param string $method Request method
* @param array $headers Request headers
*/
public static function GET($params, $method, $headers)
{
public static function GET(
\stdClass $params,
string $method,
array $headers
) {
static::handleGET(
$params,
User::class,
Expand All @@ -50,8 +53,12 @@ public static function GET($params, $method, $headers)
* @param array $headers Request headers
* @param string $id Resource id
*/
public static function GETById($params, $method, $headers, string $id)
{
public static function GETById(
\stdClass $params,
string $method,
array $headers,
string $id
) {
static::handleGETById(
$params,
$id,
Expand All @@ -70,9 +77,9 @@ public static function GETById($params, $method, $headers, string $id)
* @param string $relationship Relationship
*/
public static function byIdRelationships(
$params,
$method,
$headers,
\stdClass $params,
string $method,
array $headers,
string $id,
string $relationship
) {
Expand All @@ -88,4 +95,32 @@ public static function byIdRelationships(
[]
);
}

/**
* Access resource's relationship resources
* `/user/{id}/{relationship}/` handler
* @param \stdClass $params
* @param string $method
* @param array $headers
* @param string $id
* @param string $relationship
*/
public static function byIdRelationshipsRelated(
\stdClass $params,
string $method,
array $headers,
string $id,
string $relationship
) {
static::handleByIdRelationshipsRelated(
$params,
$method,
$headers,
$id,
$relationship,
User::class,
[\Phramework\Phramework::METHOD_GET],
[]
);
}
}
22 changes: 22 additions & 0 deletions tests/testphase/tag/get-byid-article.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"meta": {
"order": 21
},
"request": {
"url": "tag/{{tagId}}/relationships/article",
"method": "GET",
"headers": [
"{{{headerRequestAccept}}}",
"{{{headerRequestContentType}}}"
]
},
"response": {
"statusCode": 200,
"headers": {
"Content-Type": "{{{headerResponseContentType}}}"
},
"ruleObjects": [
"{{{responseBodyJsonapiResource}}}"
]
}
}
22 changes: 22 additions & 0 deletions tests/testphase/tag/get-byid-relationships-article.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"meta": {
"order": 21
},
"request": {
"url": "tag/{{tagId}}/article",
"method": "GET",
"headers": [
"{{{headerRequestAccept}}}",
"{{{headerRequestContentType}}}"
]
},
"response": {
"statusCode": 200,
"headers": {
"Content-Type": "{{{headerResponseContentType}}}"
},
"ruleObjects": [
"{{{responseBodyJsonapiResource}}}"
]
}
}