Welcome Guest, Not a member yet? Register   Sign In
REST API Design: Filtering, Sorting, and Pagination
#2

(This post was last modified: 06-11-2021, 11:51 AM by paliz.)

look all posts to understande what ive done ?? 
it has ci4 and angula11 
heres my library 

PHP Code:
<?php


namespace UQP\Interfaces;

use 
CodeIgniter\HTTP\RequestInterface;

interface 
UrlQueryParamInterface
{
    /**
    *init param
    * @param RequestInterface $request
    */
    public function initParameters(RequestInterface $request);

    //--------------------------------------------------------------------

    /**
    * get key
    *
    * @param string $function
    * @return string
    *
    */

    public function extractQueryKey(string $function): string;

    //--------------------------------------------------------------------

    /**
    * Get value.
    *
    *
    * @param string $function
    *
    * @return array
    *
    *
    */
    public function extractQueryValue(string $function): array;

    /**
    * Get value.
    *
    *
    * @param string $function
    *
    * @return array
    *
    */
    public function extractQueryArray(string $function): array;

    /**
    * Get value.
    *
    *
    * @param string $query
    * @param string $joinQuery
    *
    * @return string
    *
    *
    */
    public function extractQueryFiled(string $querystring $joinQuery): string;

    /**
    * Get value.
    * @return string
    */
    public function getFiled(): string;

    /**
    * Get value.
    * @return string
    */
    public function getOffset(): string;

    /**
    * Get value.
    * @return string
    */
    public function getLimit(): string;

    /**
    * Get value.
    * @return string
    */
    public function getOrder(): string;

    /**
    * Get value.
    * @return string
    */
    public function getSort(): string;

    /**
    * Get value.
    * @return string
    */
    public function getPage(): string;

    /**
    * Get value.
    * @param string $append
    *
    */
    public function setAppend(string $append);

    /**
    * Get value.
    * @return int
    */
    public function getForeignKey(): int;

    /**
    * Get value.
    * @param bool $flag
    * @return string
    */
    public function getRange(bool $flag): string;




PHP Code:
<?php namespace UQP\Libraries;


use 
CodeIgniter\HTTP\RequestInterface;
use 
UQP\Interfaces\UrlQueryParamInterface;


class  UrlQueryParam implements UrlQueryParamInterface
{
    private int $limit;
    private int $offset;
    private string $range;
    private int $page;
    private string $filed;
    private string $embody;
    private array $q;
    
    
private string $order;
    private string $sort;
    private int $foreignKey;
    private string $append;


    public function __construct()
    {

        $this->range '1to10';
        $this->sort 'id';
        $this->order 'desc';
        $this->page 1;
        $this->limit 10;
        $this->offset 0;
        $this->filed '*';
        $this->embody '';
        $this->= [];
        $this->foreignKey 0;
        $this->append '';
    }

    /**
    *init param
    * @param RequestInterface $request
    */
    public function initParameters(RequestInterface $request)
    {
        $this->range = isset($_GET['range']) ? $request->getGet('range') : '1to10';
        $this->sort = isset($_GET['sort']) ? $request->getGet('sort') : 'id';
        $this->order = isset($_GET['order']) ? $request->getGet('order') : 'desc';
        $this->page = isset($_GET['page']) ? $request->getGet('page') : 1;
        $this->limit = isset($_GET['limit']) ? $request->getGet('limit') : '10';
        $this->offset = isset($_GET['offset']) ? $request->getGet('offset') : '0';
        $this->filed = isset($_GET['filed']) ? $request->getGet('filed') : '*';
        $this->embody = isset($_GET['embody']) ? $request->getGet('embody') : '';
        isset($_GET['q']) ? parse_str($request->getGet('q'), $this->q) : $this->= [];
        $this->foreignKey = isset($_GET['foreignKey']) ? $request->getGet('foreignKey') : 0;
        $this->append '';
    }

    /**
    * @param string $function
    * @return string
    */
    public function extractQueryKey(string $function): string
    
{
        $temp ' ';
        $object null;
        foreach ($this->as $key => $value) {
            $object json_decode($value);
            if ($object->fun == $function) {
                $temp $key;
                $temp $this->append $temp;
            }


        }

        return $temp;
    }

    /**
    * @param string $function
    * @return array
    */
    public function extractQueryValue(string $function): array
    {
        $object null;
        $temp = [];
        foreach ($this->as $key => $value) {

            $object json_decode($value);

            if (isset($object->fun) && $object->fun == $function) {
                $temp $object->val;
            }
        }

        return $temp;
    }


    /**
    * @param string $function
    * @return array
    */
    public function extractQueryArray(string $function): array
    {
        $temp = [];
        $object null;
        $counter 0;
        foreach ($this->as $key => $value) {
            $object json_decode($value);

            if (strtolower($function) == strtolower($object->fun)) {


                if (isset($object->sgn) && !empty($object->sgn) && is_array($object->sgn)) {

                    foreach ($object->sgn as $sgn) {
                        $key $key ' ' $sgn;

                        if (isset($object->jin)) {
                            $temp[$object->jin $key] = $object->val[$counter];
                        } else {
                            $temp[$this->append $key] = $object->val[$counter];
                        }
                        $counter++;
                    }
                } else if (isset($object->sgn) && !empty($object->sgn) && is_string($object->sgn)) {

                    $key $key ' ' $object->sgn;

                    if (isset($object->jin)) {
                        $temp[$object->jin $key] = $object->val;
                    } else {
                        $temp[$this->append $key] = $object->val;
                    }
                } else {

                    if (isset($object->jin)) {
                        $temp[$object->jin $key] = $object->val;
                    } else {
                        $temp[$this->append $key] = $object->val;
                    }
                }


            }


        }
        return $temp;
    }


    public function extractQueryFiled(string $querystring $joinQuery): string
    
{


        if ($this->filed != $query && $this->embody != '') {
            return $this->filed $this->embody;
        } else if ($this->filed == $query && $this->embody != '') {
            return $this->append $query $this->embody;
        } else if ($this->filed != $query && $this->embody == '') {
            return $this->filed $joinQuery;
        } else {
            return $this->append $query $joinQuery;
        }

    }

    /**
    * @return int
    */
    public function getForeignKey(): int
    
{
        return $this->foreignKey;
    }

    /**
    * @return string
    */
    public function getFiled(): string
    
{
        return $this->filed;
    }

  

    
/**
    * @return int
    */
    public function getLimit(): string
    
{
        return $this->limit;
    }

    /**
    * @return int
    */
    public function getOffset(): string
    
{
        return $this->offset;
    }


    /**
    * @return int
    */
    public function getPage(): string
    
{
        return $this->page;
    }

    /**
    * @return string
    */
    public function getOrder(): string
    
{
        return $this->order;
    }

    /**
    * @return string
    */
    public function getSort(): string
    
{
        return $this->append $this->sort;
    }


    /**
    * @param bool $flag get segment first or second
    * @return string
    */
    public function getRange(bool $flag): string
    
{

        $result explode('to'$this->range);

        if ($flag == true) {
            return $result[0];
        } else {
            return $result[1];
        }

    }

    /**
    * @param string $append
    */
    public function setAppend(string $append)
    {
        $this->append $append;
    }



ci4 and restful ctl  
viewoprion ctl is parent
viewMedia is children 
meann i use view_oprion_id for viewMeida table  
codes 
PHP Code:
<?php

namespace CoreCommon\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *    class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */


use CodeIgniter\API\ResponseTrait;
use 
CodeIgniter\HTTP\RequestTrait;
use 
CodeIgniter\RESTful\ResourceController;
use 
Myth\Auth\AuthTrait;

use 
UQP\Interfaces\UrlQueryParamInterface;
use 
UQP\Libraries\UrlQueryParam;

class 
ApiController extends ResourceController
{
    use AuthTrait;

    protected $format "json";

    public int $userId;
    public object $userObject;
    public array $userGroup;
    public UrlQueryParamInterface $urlQueryParam;


    /**
    * Constructor.
    */
    public function __construct()
    {

        try {
            $this->setupAuthClasses();
            $this->userId $this->authenticate->id() ? $this->authenticate->id() : 0;
            $this->userObject $this->authenticate->user() ? $this->authenticate->user() : (object)[];
            $groupModel = new \Myth\Auth\Authorization\GroupModel();
            $this->userGroup $groupModel->getGroupsForUser($this->userId)[0] ? $groupModel->getGroupsForUser($this->userId)[0] : [];
            $this->urlQueryParam = new UrlQueryParam();

            $this->urlQueryParam->initParameters(\CodeIgniter\Config\Services::request());

        } catch (\Exception $e) {

        }
    }



PHP Code:
<?php


namespace CoreCommon\Controllers;


use 
CoreCommon\Entities\ViewsOptionEntity;


use 
CoreCommon\Models\ViewOptionModal;

use 
CodeIgniter\HTTP\ResponseInterface;



class 
ViewOption extends ApiController
{


    /**
    * index function
    * @method : GET
    */
    public function index()
    {
        $viewsOptionModel = new ViewOptionModal();


        $result $viewsOptionModel->select($this->urlQueryParam->getFiled())
            ->whereIn($this->urlQueryParam->extractQueryKey('in'), $this->urlQueryParam->extractQueryValue('in'))
            ->whereNotIn($this->urlQueryParam->extractQueryKey('nin'), $this->urlQueryParam->extractQueryValue('nin'))
            ->orWhereIn($this->urlQueryParam->extractQueryKey('oin'), $this->urlQueryParam->extractQueryValue('oin'))
            ->orWhereNotIn($this->urlQueryParam->extractQueryKey('onin'), $this->urlQueryParam->extractQueryValue('onin'))
            ->where($this->urlQueryParam->extractQueryArray('whr'))
            ->orWhere($this->urlQueryParam->extractQueryArray('owr'))
            ->like($this->urlQueryParam->extractQueryArray('lik'))
            ->orLike($this->urlQueryParam->extractQueryArray('olk'))
            ->orderBy($this->urlQueryParam->getSort(), $this->urlQueryParam->getOrder())
            ->paginate($this->urlQueryParam->getLimit(), 'default'$this->urlQueryParam->getPage(), $this->urlQueryParam->getOffset());


        return $this->respond([
            'data' => $viewsOptionModel->appendChildrenRows($result),
            'pager' => $viewsOptionModel->pager->getDetails()
        ], ResponseInterface::HTTP_OKlang('Common.api.receive'));


    }

    /**
    * show function
    * @method : GET with params ID
    */
    public function show($id null)
    {

        $viewsOptionModel = new ViewOptionModal();


        return $this->respond([

            'data' => $viewsOptionModel->where('id'$id)->paginate(1'default'),
            'pager' => $viewsOptionModel->pager->getDetails()
        ], ResponseInterface::HTTP_OKlang('Common.api.receive'));


    }

    /**
    * create function
    * @method : POST
    */
    public function create()
    {


// In the controller

        $viewsOptionModel = new ViewOptionModal();
        $viewsOptionEntity = new ViewsOptionEntity();
        if ($this->request->getJSON()) {
            //get request from Vue Js


            $rules = [
                'name' => 'required|max_length[255]',

            ];

            if (!$this->validate($rules)) {

                return $this->respond([
                    'error' => $this->validator->getErrors(),
                    'success' => false
                
], ResponseInterface::HTTP_NOT_ACCEPTABLElang('Common.api.validation'));

            }


            $viewsOptionEntity->name $this->request->getJSON()->name;

            if (!$viewsOptionModel->save($viewsOptionEntity)) {
                return $this->respond([
                    'error' => $viewsOptionModel->errors(),
                    'success' => false,
                ], ResponseInterface::HTTP_BAD_REQUESTlang('Common.api.reject'));

            }

            return $this->respond([
                'data' => ''
            ], ResponseInterface::HTTP_CREATEDlang('Common.api.save'));
        }


    }

    /**
    * update function
    * @method : PUT or PATCH
    */
    public function update($id null)
    {
        $viewsOptionModel = new ViewOptionModal();
        $viewsOptionEntity = new ViewsOptionEntity();
        if ($this->request->getJSON()) {
            //get request from Vue Js

            //get request from Vue Js
            $json $this->request->getJSON();
            if (!isset($id)) {
                $id $json->id;
            }


            $rules = [

                'name' => 'required|max_length[255]',
            ];

            if (!$this->validate($rules)) {

                return $this->respond([
                    'error' => $this->validator->getErrors(),
                    'success' => false
                
], ResponseInterface::HTTP_NOT_ACCEPTABLElang('Common.api.validation'));

            }


            $contacting $viewsOptionModel->asArray()->where('id'$id)->first();

            if (is_null($contacting)) {

                return $this->respond([
                    'error' => $this->validator->getErrors(),
                    'success' => false
                
], ResponseInterface::HTTP_NOT_FOUNDlang('Common.api.exist'));

            }


            $viewsOptionEntity->id $id;
            $viewsOptionEntity->name $this->request->getJSON()->name;


            if (!$viewsOptionModel->update($id$viewsOptionEntity)) {

                return $this->respond([
                    'error' => $viewsOptionModel->errors(),
                    'success' => false,
                ], ResponseInterface::HTTP_BAD_REQUESTlang('Common.api.reject'));

            }

            return $this->respond([
            ], ResponseInterface::HTTP_OKlang('Common.api.update'));
        }


    }

    /**
    * edit function
    * @method : DELETE with params ID
    */
    public function delete($id null)
    {
        $viewsOptionModel = new ViewOptionModal();


        $isExist $viewsOptionModel->find($id);
        if ($isExist) {
            // it s casecat dose not  need any thing drop all child tables
            $viewsOptionModel->delete($id);


        }

        return $this->respond([
        ], ResponseInterface::HTTP_OKlang('Common.api.remove'));


    }


PHP Code:
<?php

namespace CoreCommon\Controllers;


use 
CoreCommon\Config\CoreCommonConfig;
use 
CoreCommon\Entities\ViewsMediaEntity;
use 
CoreCommon\Libraries\CustomFileSystem;
use 
CoreCommon\Models\ViewMediaModal;
use 
CodeIgniter\HTTP\ResponseInterface;


class 
ViewMedia extends ApiController
{


    /**
    * index function
    * @method : GET
    */
    public function index()
    {

        $viewsMediaModel = new ViewMediaModal();
        $parameterDataInput = new UrlQueryParam();
        $parameterDataInput->initParameters();

        $this->urlQueryParam->setAppend('view_media.');
        $result $viewsMediaModel->select($this->urlQueryParam->extractQueryFiled'*'',view_option.name'))
            ->join('view_option''view_option.id = view_media.view_option_id''left')
            ->whereIn($this->urlQueryParam->extractQueryKey('in'), $this->urlQueryParam->extractQueryValue('in'))
            ->whereNotIn($this->urlQueryParam->extractQueryKey('nin'), $this->urlQueryParam->extractQueryValue('nin'))
            ->orWhereIn($this->urlQueryParam->extractQueryKey('oin'), $this->urlQueryParam->extractQueryValue('oin'))
            ->orWhereNotIn($this->urlQueryParam->extractQueryKey('onin'), $this->urlQueryParam->extractQueryValue('onin'))
            ->where($this->urlQueryParam->extractQueryArray('whr'))
            ->orWhere($this->urlQueryParam->extractQueryArray('owr'))
            ->like($this->urlQueryParam->extractQueryArray('lik'))
            ->orLike($this->urlQueryParam->extractQueryArray('olk'))
            ->orderBy($this->urlQueryParam->getSort(), $this->urlQueryParam->getOrder())
            ->paginate($this->urlQueryParam->getLimit(), 'default'$this->urlQueryParam->getPage(), $this->urlQueryParam->getOffset());


        return $this->respond([
            'data' => $result,
            'pager' => $viewsMediaModel->pager->getDetails()
        ], ResponseInterface::HTTP_OKlang('Common.api.receive'));


    }

    /**
    * show function
    * @method : GET with params ID
    */
    public function show($id null)
    {

        $viewsMediaModel = new ViewMediaModal();


        return $this->respond([

            'data' => $viewsMediaModel->select('view_media.*,view_option.name')->join('view_option''view_option.id = view_media.view_option_id''left')
                ->where('view_media.id'$id)->paginate(10'default'), 'pager' => $viewsMediaModel->pager->getDetails(),
            'pager' => $viewsMediaModel->pager->getDetails()
        ], ResponseInterface::HTTP_OKlang('Common.api.receive'));


    }

    /**
    * create function
    * @method : POST
    */
    public function create()
    {
        $viewsMediaModel = new ViewMediaModal();
        $customConfig = new CoreCommonConfig();
        $imageService = \CodeIgniter\Config\Services::image();
        $viewsMediaEntity = new ViewsMediaEntity();
        if ($this->request->getPost()) {
            //get request from Vue Js


            $rules = [
                'image' => 'if_exist|uploaded[image]|max_size[image,4096]|ext_in[image,png,webp,jpeg,jpg,,mp4,gif,webp]',
            ];
            if (!$this->validate($rules)) {

                return $this->respond([
                    'error' => $this->validator->getErrors(),
                    'success' => false
                
], ResponseInterface::HTTP_NOT_ACCEPTABLElang('Common.api.validation'));

            }
            $viewsMediaEntity->view_option_id $this->request->getPost('view_option_id');


            if (isset($_FILES['image'])) {


                foreach ($this->request->getFileMultiple('image') as $avatar) {

                    if ($avatar->getExtension() == 'mp4')
                        $avatar->move($customConfig->uploadDirectory '/view/video'time() . '.' $avatar->getClientExtension());
                    else
                        $avatar->move($customConfig->uploadDirectory '/view/image'time() . '.' $avatar->getClientExtension());


                    $viewsMediaEntity->path $avatar->getName();
                    $viewsMediaEntity->editPath($avatar->getExtension() != 'mp4');

                    if ($avatar->getExtension() != 'mp4' or $avatar->getExtension() != 'gif') {
                        $imageService->withFile(ROOTPATH $viewsMediaEntity->path)
                            ->withResource()
                            ->save(ROOTPATH $viewsMediaEntity->path90);


                    }
                    if (!$viewsMediaModel->save($viewsMediaEntity)) {

                        return $this->respond([
                            'error' => $viewsMediaModel->errors(),
                            'success' => false,
                        ], ResponseInterface::HTTP_BAD_REQUESTlang('Common.api.reject'));

                    }
                }


            }


            return $this->respond([
                'data' => ''
            ], ResponseInterface::HTTP_CREATEDlang('Common.api.save'));
        }

    }

    /**
    * update function
    * @method : PUT or PATCH
    */
    public function update($id null)
    {
        $viewsMediaModel = new ViewMediaModal();
        $customConfig = new CoreCommonConfig();
        $imageService = \CodeIgniter\Config\Services::image();
        $handy = new CustomFileSystem();
        $viewsMediaEntity = new ViewsMediaEntity();
        $viewsMedia null;
        if ($this->request->getPost()) {
            //get request from Vue Js

            $rules = [
                'image' => 'uploaded[image]|max_size[image,4096]|ext_in[image,png,webp,jpeg,jpg,,mp4,gif,webp]',
            ];

            if (!$this->validate($rules)) {

                return $this->respond([
                    'error' => $this->validator->getErrors(),
                    'success' => false
                
], ResponseInterface::HTTP_NOT_ACCEPTABLElang('Common.api.validation'));

            }


            $viewsMedia $viewsMediaModel->where('id'$id)->first();

            if (is_null($viewsMedia)) {
                return $this->respond([
                    'error' => $this->validator->getErrors(),
                    'success' => false
                
], ResponseInterface::HTTP_NOT_FOUNDlang('Common.api.exist'));

            }

            $viewsMediaEntity->view_option_id $this->request->getPost('view_option_id');
            $viewsMediaEntity->id $id;

            if (isset($_FILES['image'])) {

                foreach ($this->request->getFileMultiple('image') as $avatar) {


                    if ($avatar->getExtension() == 'mp4')
                        $avatar->move($customConfig->uploadDirectory '/view/video'time() . '.' $avatar->getClientExtension());
                    else
                        $avatar->move($customConfig->uploadDirectory '/view/image'time() . '.' $avatar->getClientExtension());


                    $viewsMediaEntity->path $avatar->getName();
                    $viewsMediaEntity->editPath($avatar->getExtension() != 'mp4');

                    if ($avatar->getExtension() != 'mp4' or $avatar->getExtension() != 'gif') {

                        $imageService->withFile(ROOTPATH $viewsMediaEntity->path)
                            ->withResource()
                            ->save(ROOTPATH $viewsMediaEntity->path90);

                    }


                }
                $handy->removeSingleFile(ROOTPATH $viewsMedia->path);

                if (!$viewsMediaModel->update($id$viewsMediaEntity)) {

                    return $this->respond([
                        'error' => $viewsMediaModel->errors(),
                        'success' => false,
                    ], ResponseInterface::HTTP_BAD_REQUESTlang('Common.api.reject'));

                }

            }


            return $this->respond([
            ], ResponseInterface::HTTP_OKlang('Common.api.update'));
        }


    }

    /**
    * edit function
    * @method : DELETE with params ID
    */
    public function delete($id null)
    {


        $viewsMediaModel = new ViewMediaModal();
        $handy = new CustomFileSystem();


        $id = ($id == $id);

        if ($id == 0) {

            $isExist $viewsMediaModel->where(['view_option_id' => $this->urlQueryParam->getForeignKey()])->
            findAll();
            $target = array('view_option_id' => $this->urlQueryParam->getForeignKey());
        } else {
            $isExist $viewsMediaModel->where(['id' => $id])->findAll();
            $target = array('id' => $id);
        }


        if ($isExist) {
            $viewsMediaModel->where($target)->delete();
            foreach ($isExist as $path) {

                $handy->removeSingleFile(ROOTPATH $path->path);
            }


        }

        return $this->respond([
        ], ResponseInterface::HTTP_OKlang('Common.api.remove'));


    }



angular code look at  

Code:
onSubmitAdvanceSearch(): void {
    this.subscription = this.settingService.getQueryArgumentObservable().subscribe((qParams) => {


      this.sortValue = qParams.sort;
      this.orderValue = qParams.order;
    });


    if (this.formAdvanceSearch.invalid) {
      return;
    }
    this.submitted2 = true;
    const compressSearchForm = CompressSearchForm(this.formAdvanceSearch);
    let queryParam = new HttpParams();

    for (let i = 0; i < compressSearchForm.value._data.length; i++) {
      const search: ISearch = {
        fun: compressSearchForm.value._function,
        sgn: compressSearchForm.value._data[i]._sign,
        val: compressSearchForm.value._data[i]._value,
      };

      queryParam = queryParam.append(compressSearchForm.value._data[i]._field, JSON.stringify(search));
    }
    this.modalRef.hide();

    const params: IQuery = {
      page: 1,
      sort: this.sortValue,
      order: this.orderValue,
      q: queryParam
    };
    this.settingService.setQueryArgument(params);
    this.router.navigate(['./admin/setting/list'], {
      queryParams: params,

    });

  }

Code:
import {FormGroup} from '@angular/forms';

export function CompressSearchForm(formRaw: FormGroup): FormGroup {

  let index = 0;
  let Yandex = 0;
  let length = formRaw.value._data.length;
  const dummies = formRaw;
  const func = formRaw.value._function;
  while (true) {
    const arr1 = [];
    const arr2 = [];

    if (length <= 1) {
      break;
    }


    while (true) {
      if (formRaw.value._data[index]._field === formRaw.value._data[Yandex + 1]._field) {

        if (func === 'whr' || func === 'owr') {
          arr2.push(formRaw.value._data[index]._sign);
          arr2.push(formRaw.value._data[Yandex + 1]._sign);
        } else {
          arr2.push('');
          arr2.push('');

        }

        arr1.push(formRaw.value._data[index]._value);
        arr1.push(formRaw.value._data[Yandex + 1]._value);

        dummies.value._data[index]._value = arr1;
        dummies.value._data[index]._sign = arr2;
        delete dummies.value._data[Yandex + 1];
        break;
      }

      if (Yandex + 1 < length) {
        break;
      }
      Yandex++;

    }


    formRaw = dummies;
    length = formRaw.value._data.length;

    if (index < length) {
      break;
    }
    index++;

  }
  formRaw.value._data = formRaw.value._data.filter(() => true);
  return formRaw;
}


Code:
onSubmit(): void {
    this.subscription = this.settingService.getQueryArgumentObservable().subscribe((qParams) => {


      this.sortValue = qParams.sort;
      this.orderValue = qParams.order;
    });

    if (this.formGroup.invalid) {
      return;
    }
    this.submitted = true;

    const search: ISearch = {
      fun: 'lik',
      sgn: '',
      val: this.formGroup.value._key
    };


    const queryParam = new HttpParams().append(this.sortValue, JSON.stringify(search));
    const params: IQuery = {
      page: 1,
      sort: this.sortValue,
      order: this.orderValue,
      q: queryParam
    };
    this.settingService.setQueryArgument(params);
    this.router.navigate(['./admin/setting/list'], {
      queryParams: params,

    });

  }

the code has been tested by me work 100000000000000% enjoy

last part you need add this line to base baseBuilder.php class 
first function is  _whereIn()

PHP Code:
protected function _whereIn(string $key null$values nullbool $not falsestring $type 'AND 'bool $escape nullstring $clause 'QBWhere')
    {
        if (empty($key) || !is_string($key)) {
            if (CI_DEBUG) {
                throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string'debug_backtrace(02)[1]['function']));
            }
            // @codeCoverageIgnoreStart
            return $this;
            // @codeCoverageIgnoreEnd
        }

        if ($values === null || (!is_array($values) && !($values instanceof Closure))) {
            if (CI_DEBUG) {
                throw new InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure'debug_backtrace(02)[1]['function']));
            }
            // @codeCoverageIgnoreStart
            return $this;
            // @codeCoverageIgnoreEnd
        }
           // look here 
        /// add this line
        if (is_array($values) && empty($values)) {

            return $this;

        }... 

and change this function too whereHaving()


PHP Code:
protected function whereHaving(string $qbKey$key$value nullstring $type 'AND 'bool $escape null)
    {
// loookkkk herererere
        // add  line coode
        if (is_array($key) && empty($key)) {

            return $this;

        


finally _like()
PHP Code:
protected function _like($fieldstring $match ''string $type 'AND 'string $side 'both'string $not ''bool $escape nullbool $insensitiveSearch falsestring $clause 'QBWhere')
    {
        //add  this line
         // look hererererere
        if (is_array($field) && empty($field)) {
            return $this;

        


these change make sure if there no data just ignore validation
Enlightenment  Is  Freedom
Reply


Messages In This Thread
RE: REST API Design: Filtering, Sorting, and Pagination - by paliz - 06-11-2021, 11:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB