register_endpoint( 'profile', [ $this, 'get_profile' ] ); $this->get( 'profile/download-history', [ $this, 'get_download_history' ] ); $this->get( 'profile/my-favourites', [ $this, 'get_my_favourites' ] ); } public function get_profile( WP_REST_Request $request ) { } public function get_download_history() { $page = $this->get_param( 'page', 1, 'intval' ); $per_page = $this->get_param( 'per_page', 10, 'intval' ); $response = $this->http()->mutation( 'myDownloadHistory', 'data{ name, thumbnail, downloaded_at, slug, type }, current_page, total_page', [ 'api_key' => $this->api_key, 'per_page' => $per_page, "page" => $page ] )->post(); if ( is_wp_error( $response ) ) { return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history', $response->get_error_code() ); } return $response; } public function get_my_favourites() { $type = $this->get_param( 'itemType', 'all' ); $plan = $this->get_param( 'plan', 'all' ); $plan_type = $this->get_plan( $plan ); $page = $this->get_param( 'page', 1, 'intval' ); $per_page = $this->get_param( 'per_page', 20, 'intval' ); $funcArgs = [ 'api_key' => $this->api_key, "page" => $page, "per_page" => $per_page, "plan_type" => $plan_type ]; if( $type != 'all' ) { $funcArgs['type'] = $type; } $response = $this->http()->mutation( 'myFavouriteItem', 'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined } }', $funcArgs )->post(); if ( is_wp_error( $response ) ) { return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() ); } return $response; } }