Now the routes accept queries
This commit is contained in:
parent
9675dd8b90
commit
fcaaaf0438
|
@ -41,20 +41,20 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_item_schema()
|
||||
//'args' => $this->get_item_schema()
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
//'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
),
|
||||
));
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<collection_id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
),
|
||||
array(
|
||||
|
@ -78,17 +78,18 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items($request){
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filters = $body['filters'];
|
||||
$map = $this->collections_repository->get_map();
|
||||
|
||||
$map = $this->collections_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filters, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$collections = $this->collections_repository->fetch($args);
|
||||
|
||||
$response = $this->prepare_item_for_response($collections, $request);
|
||||
|
|
|
@ -59,7 +59,7 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
|
@ -174,17 +174,18 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
public function get_items( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filters = $body['filters'];
|
||||
$map = $this->field_repository->get_map();
|
||||
|
||||
$map = $this->field_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filters, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$collection = new Entities\Collection($collection_id);
|
||||
|
||||
$collection_metadata = $this->field_repository->fetch_by_collection($collection, $args, 'OBJECT');
|
||||
|
|
|
@ -273,17 +273,18 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filtersq = $body['filters'];
|
||||
$map = $this->filter_repository->get_map();
|
||||
|
||||
$map = $this->filter_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filtersq, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$filters = $this->filter_repository->fetch($args, 'OBJECT');
|
||||
|
||||
$response = $this->prepare_item_for_response($filters, $request);
|
||||
|
|
|
@ -54,7 +54,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -47,15 +47,15 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
//'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
),
|
||||
'schema' => array($this, 'get_public_item_schema'),
|
||||
//'schema' => array($this, 'get_public_item_schema'),
|
||||
));
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<item_id>[\d]+)',
|
||||
|
@ -105,7 +105,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
return $items;
|
||||
} elseif(!empty($item)){
|
||||
return $this->get_only_needed_attributes($item, $map);
|
||||
return $item->__toArray();
|
||||
}
|
||||
|
||||
return $item;
|
||||
|
@ -132,17 +132,18 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filters = $body['filters'];
|
||||
$map = $this->items_repository->get_map();
|
||||
|
||||
$map = $this->items_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filters, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$collection_id = $request['collection_id'];
|
||||
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
|
||||
|
||||
|
|
|
@ -72,17 +72,17 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filters = $body['filters'];
|
||||
$map = $this->logs_repository->get_map();
|
||||
|
||||
$map = $this->logs_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filters, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$logs = $this->logs_repository->fetch($args, 'OBJECT');
|
||||
|
||||
if(!empty($logs)) {
|
||||
|
|
|
@ -204,17 +204,18 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filters = $body['filters'];
|
||||
$map = $this->taxonomy_repository->get_map();
|
||||
|
||||
$map = $this->taxonomy_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filters, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$taxonomies = $this->taxonomy_repository->fetch($args, 'OBJECT');
|
||||
|
||||
$taxonomies_prepared = $this->prepare_item_for_response($taxonomies, $request);
|
||||
|
|
|
@ -262,17 +262,18 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$taxonomy = $this->taxonomy_repository->fetch($taxonomy_id);
|
||||
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if(isset($body['filters'])) {
|
||||
$filters = $body['filters'];
|
||||
$map = $this->terms_repository->get_map();
|
||||
|
||||
$map = $this->terms_repository->get_map();
|
||||
|
||||
$args = $this->unmap_filters($filters, $map);
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$terms = $this->terms_repository->fetch($args, $taxonomy);
|
||||
|
||||
$prepared_terms = $this->prepare_item_for_response($terms, $request);
|
||||
|
|
|
@ -148,17 +148,13 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
|||
true
|
||||
);
|
||||
|
||||
$show_empty = json_encode([
|
||||
'filters' => [
|
||||
'hide_empty' => false
|
||||
]
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms'
|
||||
);
|
||||
|
||||
$request->set_body($show_empty);
|
||||
$request->set_query_params([
|
||||
'hide_empty' => false
|
||||
]);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
|
|
Loading…
Reference in New Issue