Get a filter

This commit is contained in:
weryques 2018-01-18 11:23:16 -02:00
parent ab081cc992
commit a37e56e424
3 changed files with 34 additions and 11 deletions

View File

@ -55,6 +55,11 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller {
'methods' => WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item'),
'permission_callback' => array($this, 'update_item_permissions_check')
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check')
)
));
}
@ -252,5 +257,18 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller {
public function get_items_permissions_check( $request ) {
return $this->filter_repository->can_read($this->filter);
}
public function get_item( $request ) {
$filter_id = $request['filter_id'];
$filter = $this->filter_repository->fetch($filter_id);
return new WP_REST_Response($filter->__toArray(), 200);
}
public function get_item_permissions_check( $request ) {
$filter = $this->filter_repository->fetch($request['filter_id']);
return $this->filter_repository->can_read($filter);
}
}
?>

View File

@ -233,20 +233,13 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller {
$taxonomy = $this->taxonomy_repository->fetch($taxonomy_id);
if(!empty($taxonomy)){
$args = json_decode($request->get_body(), true);
$args = json_decode($request->get_body(), true);
$terms = $this->terms_repository->fetch($args, $taxonomy);
$terms = $this->terms_repository->fetch($args, $taxonomy);
$prepared_terms = $this->prepare_item_for_response($terms, $request);
$prepared_terms = $this->prepare_item_for_response($terms, $request);
return new WP_REST_Response($prepared_terms, 200);
}
return new WP_REST_Response([
'error_message' => "Taxonomy with this id ($taxonomy_id) not found.",
'taxonomy_id' => $taxonomy_id
], 400);
return new WP_REST_Response($prepared_terms, 200);
}
/**

View File

@ -234,6 +234,18 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals($filter2->get_name(), $first_filter['name']);
$this->assertEquals($filter->get_name(), $second_filter['name']);
#### FETCH ONE FILTER ####
$request = new \WP_REST_Request(
'GET', $this->namespace . '/filters/' . $filter->get_id()
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals('filtro', $data['name']);
}
}