-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
References and endpoints for dataset properties and dynamic API routi…
…ng (#129)
- Loading branch information
1 parent
20045ce
commit be785f0
Showing
26 changed files
with
1,596 additions
and
911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,3 @@ | ||
dkan_api.dataset_get_all: | ||
path: '/api/v1/dataset' | ||
methods: [GET] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Dataset::getAll'} | ||
requirements: | ||
_access: 'TRUE' | ||
dkan_api.dataset_get: | ||
path: '/api/v1/dataset/{uuid}' | ||
methods: [GET] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Dataset::get'} | ||
requirements: | ||
_access: 'TRUE' | ||
dkan_api.dataset_post: | ||
path: '/api/v1/dataset' | ||
methods: [POST] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Dataset::post'} | ||
options: | ||
_auth: [ 'basic_auth' ] | ||
requirements: | ||
_permission: 'post put delete datasets through the api' | ||
dkan_api.dataset_put: | ||
path: '/api/v1/dataset/{uuid}' | ||
methods: [PUT] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Dataset::put'} | ||
options: | ||
_auth: [ 'basic_auth' ] | ||
requirements: | ||
_permission: 'post put delete datasets through the api' | ||
dkan_api.dataset_patch: | ||
path: '/api/v1/dataset/{uuid}' | ||
methods: [PATCH] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Dataset::patch'} | ||
options: | ||
_auth: [ 'basic_auth' ] | ||
requirements: | ||
_permission: 'post put delete datasets through the api' | ||
dkan_api.dataset_delete: | ||
path: '/api/v1/dataset/{uuid}' | ||
methods: [DELETE] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Dataset::delete'} | ||
options: | ||
_auth: [ 'basic_auth' ] | ||
requirements: | ||
_permission: 'post put delete datasets through the api' | ||
dkan_api.organization_get: | ||
path: '/api/v1/organization' | ||
methods: [GET] | ||
defaults: | ||
{ _controller: '\Drupal\dkan_api\Controller\Organization::getAll'} | ||
requirements: | ||
_access: 'TRUE' | ||
# Dynamic routes based on dkan_json_property_api's property_list config. | ||
route_callbacks: | ||
- '\Drupal\dkan_api\Routing\RouteProvider::routes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Drupal\dkan_api\Routing; | ||
|
||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
/** | ||
* | ||
*/ | ||
class RouteProvider { | ||
|
||
/** | ||
* @return array | ||
* list of json properties being considered from DKAN json property api | ||
* config value. | ||
* | ||
* @Todo: consolidate with dkan_data ValueReferencer's getPropertyList. | ||
*/ | ||
public function getPropertyList() { | ||
$list = \Drupal::config('dkan_data.settings')->get('property_list'); | ||
if ($list) { | ||
// Trim and split list on newlines whether Windows, MacOS or Linux. | ||
return preg_split( | ||
'/\s*\r\n\s*|\s*\r\s*|\s*\n\s*/', | ||
trim($list), | ||
-1, | ||
PREG_SPLIT_NO_EMPTY | ||
); | ||
} | ||
else { | ||
return []; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function routes() { | ||
$routes = new RouteCollection(); | ||
$public_routes = new RouteCollection(); | ||
$authenticated_routes = new RouteCollection(); | ||
$schemas = array_merge(['dataset'], $this->getPropertyList()); | ||
|
||
foreach ($schemas as $schema) { | ||
// GET collection. | ||
$get_all = $this->routeHelper($schema, "/api/v1/$schema", 'GET', 'getAll'); | ||
$public_routes->add("dkan_api.{$schema}.get_all", $get_all); | ||
// GET individual. | ||
$get = $this->routeHelper($schema, "/api/v1/$schema/{uuid}", 'GET', 'get'); | ||
$public_routes->add("dkan_api.{$schema}.get", $get); | ||
// POST. | ||
$post = $this->routeHelper($schema, "/api/v1/$schema", 'POST', 'post'); | ||
$authenticated_routes->add("dkan_api.{$schema}.post", $post); | ||
// PUT. | ||
$put = $this->routeHelper($schema, "/api/v1/$schema/{uuid}", 'PUT', 'put'); | ||
$authenticated_routes->add("dkan_api.{$schema}.put", $put); | ||
// PATCH. | ||
$patch = $this->routeHelper($schema, "/api/v1/$schema/{uuid}", 'PATCH', 'patch'); | ||
$authenticated_routes->add("dkan_api.{$schema}.patch", $patch); | ||
// DELETE. | ||
$delete = $this->routeHelper($schema, "/api/v1/$schema/{uuid}", 'DELETE', 'delete'); | ||
$authenticated_routes->add("dkan_api.{$schema}.delete", $delete); | ||
} | ||
|
||
$public_routes->addRequirements(['_access' => 'TRUE']); | ||
$authenticated_routes->addRequirements(['_permission' => 'post put delete datasets through the api']); | ||
$authenticated_routes->addOptions(['_auth' => ['basic_auth']]); | ||
$routes->addCollection($public_routes); | ||
$routes->addCollection($authenticated_routes); | ||
|
||
return $routes; | ||
} | ||
|
||
/** | ||
* @param string $path | ||
* @param string $datasetMethod | ||
* @param string $httpVerb | ||
* @return Route | ||
*/ | ||
protected function routeHelper(string $schema, string $path, string $httpVerb, string $datasetMethod) : Route { | ||
$route = new Route( | ||
$path, | ||
[ | ||
'_controller' => '\Drupal\dkan_api\Controller\Dataset::' . $datasetMethod, | ||
'schema_id' => $schema, | ||
] | ||
); | ||
$route->setMethods([$httpVerb]); | ||
return $route; | ||
} | ||
|
||
} |
Oops, something went wrong.