| | |
| | | Route::for('favourites') |
| | | ->get([$this, 'getFavourites']) |
| | | ->args([ |
| | | 'user' => 'integer|required', |
| | | 'type' => 'string', |
| | | 'include_all' => 'boolean', |
| | | ]) |
| | |
| | | ->rateLimit(30) |
| | | ->post([$this, 'handleFavourite']) |
| | | ->args([ |
| | | 'user' => 'integer|required', |
| | | 'action' => 'string|required|enum:add,remove,toggle,batch,note', |
| | | 'type' => 'string', |
| | | 'target_id' => 'integer', |
| | |
| | | ->rateLimit(30) |
| | | ->post([$this, 'handleList']) |
| | | ->args([ |
| | | 'user' => 'integer|required', |
| | | 'id' => 'string|required', |
| | | 'action' => 'string|required|enum:create,update,delete,share,unshare,add_items,remove_items', |
| | | 'list_id' => 'integer', |
| | |
| | | // Favourite counts |
| | | Route::for('favourites/counts') |
| | | ->get([$this, 'getFavouriteCounts']) |
| | | ->args(['user' => 'integer|required']) |
| | | ->auth(PermissionHandler::combine(['user', ['actionNonce' => 'favourites-']])) |
| | | ->register(); |
| | | } |
| | |
| | | */ |
| | | public function getFavourites(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | $user_id = absint($request->get_param('user')); |
| | | $user_id = get_current_user_id(); |
| | | |
| | | if (!$this->userCheck($user_id)) { |
| | | if (!$user_id) { |
| | | return $this->unauthorized(); |
| | | } |
| | | |
| | |
| | | public function handleFavourite(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | $params = $request->get_params(); |
| | | $user_id = absint($params['user']??0); |
| | | $user_id = get_current_user_id(); |
| | | |
| | | if (!$this->userCheck($user_id)) { |
| | | return $this->unauthorized(); |
| | | } |
| | | $action = strtolower(sanitize_text_field($params['action'])); |
| | | $action = in_array($action, ['add', 'remove']) ? $action : false; |
| | | if (!$action) { |
| | |
| | | public function getLists(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | $params = $request->get_params(); |
| | | $user_id = absint($params['user']); |
| | | $user_id = get_current_user_id(); |
| | | |
| | | if (!$this->userCheck($user_id)) { |
| | | return $this->unauthorized(); |
| | | } |
| | | |
| | | $args = $this->buildParams($request); |
| | | $args['per_page'] = 20; |
| | |
| | | public function getFavouriteCounts(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | |
| | | $user_id = absint($request->get_param('user')); |
| | | $user_id = get_current_user_id(); |
| | | |
| | | if (!$this->userCheck($user_id)) { |
| | | return $this->unauthorized(); |
| | | } |
| | | |
| | | $counts = JVB()->favourites()->getFavouriteCounts($user_id); |
| | | |
| | |
| | | protected function buildParams(WP_REST_Request $request): array |
| | | { |
| | | $data = $request->get_params(); |
| | | |
| | | $where = ['user_id' => absint($data['user'])]; |
| | | $userID = get_current_user_id(); |
| | | if(!$userID) { |
| | | return []; |
| | | } |
| | | $where = ['user_id' => $userID]; |
| | | if (!empty($data['content']) && $data['content'] !== 'all') { |
| | | $where['type'] = BASE . $data['content']; |
| | | } |
| | |
| | | */ |
| | | public function handleList(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | $user_id = absint($request->get_param('user')); |
| | | $user_id = get_current_user_id(); |
| | | $operation_id = sanitize_text_field($request->get_param('id')); |
| | | $action = sanitize_text_field($request->get_param('action')); |
| | | |