8000 Add process validation · CodingSeo/laravel-json-api@df9bd17 · GitHub
[go: up one dir, main page]

Skip to content

Commit df9bd17

Browse files
committed
Add process validation
1 parent 47d5f6a commit df9bd17

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

src/Http/Requests/FetchProcess.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace CloudCreativity\LaravelJsonApi\Http\Requests;
1919

20+
use CloudCreativity\LaravelJsonApi\Contracts\Validators\ValidatorProviderInterface;
21+
2022
/**
2123
* Class FetchResource
2224
*
@@ -33,4 +35,25 @@ public function getProcessId(): string
3335
return $this->jsonApiRequest->getProcessId();
3436
}
3537

38+
/**
39+
* @inheritDoc
40+
*/
41+
protected function validateQuery()
42+
{
43+
if (!$validators = $this->getValidators()) {
44+
return;
45+
}
46+
47+
/** Pre-1.0 validators */
48+
if ($validators instanceof ValidatorProviderInterface) {
49+
$validators->resourceQueryChecker()->checkQuery($this->getEncodingParameters());
50+
return;
51+
}
52+
53+
/** 1.0 validators */
54+
$this->passes(
55+
$validators->fetchQuery($this->query())
56+
);
57+
}
58+
3659
}

src/Http/Requests/FetchProcesses.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace CloudCreativity\LaravelJsonApi\Http\Requests;
1919

20+
use CloudCreativity\LaravelJsonApi\Contracts\Validators\ValidatorProviderInterface;
21+
2022
/**
2123
* Class FetchResources
2224
*
@@ -55,15 +57,30 @@ protected function authorize()
5557
*/
5658
protected function validateQuery()
5759
{
58-
// @TODO
59-
// if (!$validators = $this->getValidators()) {
60-
// return;
61-
// }
62-
//
63-
// /** 1.0 validators */
64-
// $this->passes(
65-
// $validators->fetchManyQuery($this->query())
66-
// );
60+
if (!$validators = $this->getValidators()) {
61+
return;
62+
}
63+
64+
/** Pre-1.0 validators */
65+
if ($validators instanceof ValidatorProviderInterface) {
66+
$validators->searchQueryChecker()->checkQuery($this->getEncodingParameters());
67+
return;
68+
}
69+
70+
/** 1.0 validators */
71+
$this->passes(
72+
$validators->fetchManyQuery($this->query())
73+
);
74+
}
75+
76+
/**
77+
* @inheritdoc
78+
*/
79+
protected function getValidators()
80+
{
81+
return $this->container->getValidatorsByResourceType(
82+
$this->getProcessType()
83+
);
6784
}
6885

6986
}

src/Http/Requests/ValidatedRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ abstract class ValidatedRequest implements ValidatesWhenResolved
5555
/**
5656
* @var ContainerInterface
5757
*/
58-
private $container;
58+
protected $container;
5959

6060
/**
6161
* Authorize the request.

src/Resources/QueueJobs/Validators.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ protected function queryRules(): array
4444
return [];
4545
}
4646

47-
4847
}

tests/lib/Integration/Queue/QueueJobsTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ public function testReadNotFound()
6868
->assertStatus(404);
6969
}
7070

71+
public function testInvalidInclude()
72+
{
73+
$job = factory(ClientJob::class)->create();
74+
75+
$this->getJsonApi($this->jobUrl($job) . '?' . http_build_query(['include' => 'foo']))
76+
->assertStatus(400);
77+
}
78+
7179
/**
7280
* @param ClientJob $job
7381
* @param string|null $resourceType

0 commit comments

Comments
 (0)
0