Fetch a Term
This commit is contained in:
parent
a37e56e424
commit
15612ef35a
|
@ -258,6 +258,11 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller {
|
|||
return $this->filter_repository->can_read($this->filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$filter_id = $request['filter_id'];
|
||||
|
||||
|
@ -266,6 +271,11 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller {
|
|||
return new WP_REST_Response($filter->__toArray(), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$filter = $this->filter_repository->fetch($request['filter_id']);
|
||||
return $this->filter_repository->can_read($filter);
|
||||
|
|
|
@ -50,6 +50,11 @@ class TAINACAN_REST_Terms_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')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -251,6 +256,32 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller {
|
|||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
return $this->taxonomy_repository->can_read($taxonomy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$term_id = $request['term_id'];
|
||||
$tax_id = $request['taxonomy_id'];
|
||||
|
||||
$taxonomy = $this->taxonomy_repository->fetch($tax_id);
|
||||
|
||||
$term = $this->terms_repository->fetch($term_id, $taxonomy);
|
||||
|
||||
return new WP_REST_Response($term->__toArray(), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
return $this->taxonomy_repository->can_read($taxonomy);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -235,7 +235,7 @@ 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 ####
|
||||
#### FETCH A FILTER ####
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->namespace . '/filters/' . $filter->get_id()
|
||||
|
|
|
@ -135,7 +135,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
|||
true
|
||||
);
|
||||
|
||||
$this->tainacan_entity_factory->create_entity(
|
||||
$term2 = $this->tainacan_entity_factory->create_entity(
|
||||
'term',
|
||||
array(
|
||||
'taxonomy' => $taxonomy->get_db_identifier(),
|
||||
|
@ -164,6 +164,18 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$this->assertEquals('Trap', $termB['name']);
|
||||
$this->assertEquals('Rock', $termA['name']);
|
||||
|
||||
#### FETCH A TERM ####
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->namespace . '/terms/' . $term2 . '/taxonomy/' . $taxonomy->get_id()
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals('Trap', $data['name']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue