Skip to content

Commit

Permalink
Only register routes from api resource controller that implements the…
Browse files Browse the repository at this point in the history
… RestController action

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Nov 12, 2022
1 parent f5218f8 commit 0b467b7
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions classes/ApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Igniter\Api\Models\Resource;
use Igniter\Flame\Traits\Singleton;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function buildResource($name, $model, $meta = [])
$singularController = str_singular($controller);
$namespace = '\\Igniter\\Api\\ApiResources';

\Artisan::call('create:apiresource', [
Artisan::call('create:apiresource', [
'extension' => 'Igniter.Api',
'controller' => $controller,
'--model' => $model,
Expand All @@ -78,17 +79,24 @@ public function buildResource($name, $model, $meta = [])

protected function loadResources()
{
$resources = Resource::all()->mapWithKeys(function ($resource) {
$resourceObj = (object)[
'endpoint' => $resource->endpoint,
'controller' => $resource->controller,
'options' => array_merge($resource->meta, [
'only' => $resource->getAvailableActions(),
]),
];

return [$resource->endpoint => $resourceObj];
});
$resources = Resource::all()
->filter(function ($resource) {
return resolve($resource->controller)->isClassExtendedWith('Igniter.Api.Actions.RestController');
})
->filter(function ($resource) {
return count($resource->getAvailableActions()) > 0;
})
->mapWithKeys(function ($resource) {
$resourceObj = (object)[
'endpoint' => $resource->endpoint,
'controller' => $resource->controller,
'options' => array_merge($resource->meta, [
'only' => $resource->getAvailableActions(),
]),
];

return [$resource->endpoint => $resourceObj];
});

$this->resources = $resources;
}
Expand Down

0 comments on commit 0b467b7

Please sign in to comment.