Giter Club home page Giter Club logo

dingoquerymapper's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dingoquerymapper's Issues

Nested Filtering

Hi,

How can I use Filtering for Nested response ?

See this :

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "[email protected]",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
  {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "[email protected]",
    "address": {
      "street": "Victor Plains",
      "suite": "Suite 879",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": {
        "lat": "-43.9509",
        "lng": "-34.4618"
      }
    },
    "phone": "010-692-6593 x09125",
    "website": "anastasia.net",
    "company": {
      "name": "Deckow-Crist",
      "catchPhrase": "Proactive didactic contingency",
      "bs": "synergize scalable supply-chains"
    }
  },
  {
    "id": 3,
    "name": "Clementine Bauch",
    "username": "Samantha",
    "email": "[email protected]",
    "address": {
      "street": "Douglas Extension",
      "suite": "Suite 847",
      "city": "McKenziehaven",
      "zipcode": "59590-4157",
      "geo": {
        "lat": "-68.6102",
        "lng": "-47.0653"
      }
    },
    "phone": "1-463-123-4447",
    "website": "ramiro.info",
    "company": {
      "name": "Romaguera-Jacobson",
      "catchPhrase": "Face to face bifurcated interface",
      "bs": "e-enable strategic applications"
    }
  },
  {
    "id": 4,
    "name": "Patricia Lebsack",
    "username": "Karianne",
    "email": "[email protected]",
    "address": {
      "street": "Hoeger Mall",
      "suite": "Apt. 692",
      "city": "South Elvis",
      "zipcode": "53919-4257",
      "geo": {
        "lat": "29.4572",
        "lng": "-164.2990"
      }
    },
    "phone": "493-170-9623 x156",
    "website": "kale.biz",
    "company": {
      "name": "Robel-Corkery",
      "catchPhrase": "Multi-tiered zero tolerance productivity",
      "bs": "transition cutting-edge web services"
    }
  }
]

My controller:

$users = User::with('address')->with('company')->get();

$qm = new DingoQueryMapper($request);

$users = $qm->createFromCollection($users)->paginate();

I need retrieve city based on query I enter in URL, ex:

{{host}}/api/users?address[city]=Jakarta

Its not working, is still retrieve all of user data.

Can you help me for nested filtering ?

Edit (johannessschobel):
I have removed some entities in order to "shrink" down the issue message.

Case Insensitive Searching

Hello, I am trying to do a search on a column named 'customername', but the values in the database are either uppercase or lowercase, is there any way to do a case INSENSITIVE search?

{{url}}/loads?sort=id&limit=100&customername=TORRES*

^ This will bring back records with 'TORRES' in the customername but not records with the a lower case 'torres'.

specific columns

How can i get specific columns in DingoQueryMapperBuilder

code like below :

        $orders = Order::whereNotNull('id');

        $qm = new DingoQueryMapperBuilder($request);

        return $qm->createFromBuilder($orders)->paginate()

PSR2 Standards

Hey,

I've noticed this package isn't compatible with PSR2 code standards.

I've gone ahead and forked to make it comparable.

Sorting relations

Hey,

Is it possible to sort relations?

e.g /api/v1/events?sort=team.name or /api/v1/events?sort=team[name]

I've tried using both but they seem to throw errors.

Cheers

Adding more fuzzy matching

Well, another one @johannesschobel :)

When working with the custom filters you now have the possibility to filter on strings 'starting with' using the String* filter. I have a lot of cases where I need a bit more fuzzy matching, for example matching a part of a string: 'A beautiful song I wrote'.

I would suggest expanding the createEvaluationRule method, listening for *String*, to fit this purpose?

private function createEvaluationRule($key, $operator, $value)
    {
        // first, check the operator type!
        if ($operator == '=') {
            $operator = '==';
        }

        // escaping
        $key = addslashes($key);

        $rule = "'%s' %s '%s'"; // key, operator, value
        $rule = sprintf($rule, $key, $operator, $value);

        // now check if the operator was "(not) like"?
        if (strpos($operator, 'like') !== false) {

            // check for %value% to perform a more fuzzy match
            if (preg_match('/%(.*).{1,}?%/', $value)) {

                $value = str_replace('%', '', $value);
                $rule = "%sis_int(stripos('%s', '%s')) ? true : false";

                $expectedResult = '';

                if (stripos($operator, 'not') !== false) {
                    // it is a NOT LIKE operator
                    $expectedResult = '!';
                }

                $rule = sprintf($rule, $expectedResult, $key, $value);

            } else {
                $value = str_replace('%', '', $value);    
                $rule = "substr('%s', 0, strlen('%s')) %s '%s'"; // haystack, $needle, $comparable, $needle

                $expectedResult = '===';

                if (stripos($operator, 'not') !== false) {
                    // it is a NOT LIKE operator
                    $expectedResult = '!==';
                }

                $rule = sprintf($rule, $key, $value, $expectedResult, $value);
            }  
        }

        return $rule;
    }

If you like the idea I can send in another PR?

Null / Not Null Operators

Hey,

I'm using this package in a project and I've just run into an issue where I need to get results where a column is null (and also not null).

I'm happy to do the PR for it, but I'm wondering what operators you'd suggest/rather have.

Single quoted content and filtering

I encountered an issue when filtering a Collection using the createFromCollection method from your DingoQueryMapper. When there are model params with single quoted content, building the filtering rules seems to break.

I think the problem is in the createEvaluationRule method from the CollectionOperator. When building an evaluation rule, where the key contains a single quote, the endresult is a string which cannot be evaluated. I can solve this by stripping any single quotes from the $key parameter, before further building the rule in createEvaluationRule.

Just to be sure, am I doing something wrong here or did I just found a bug ;). Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.