Code Monkey home page Code Monkey logo

api-filter-bundle's People

Contributors

fd6130 avatar gadixsystem avatar monterhealth avatar simopich avatar stef-gijsberts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

api-filter-bundle's Issues

\MonterHealth\ApiFilterBundle\MonterHealthApiFilter::applyFilterResults does not deal correctly properties annotated with \Doctrine\ORM\Mapping\Embedded

Doctrine has a cool feature for separating concerns called Embeddables

take in example the scenario described at https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/tutorials/embeddables.html and add a cotroller to retrieve users by api

<?php
use Doctrine\ORM\Mapping as ORM;
use MonterHealth\ApiFilterBundle\Annotation\ApiFilter;
use MonterHealth\ApiFilterBundle\Filter\SearchFilter;
/** 
 * @ORM\Entity(repositoryClass=UserRepository::class)
 * @ApiFilter(SearchFilter::class, properties={
 *     "address"
 *
 * }) */
class User
{
    /** @ORM\Embedded(class = "Address") */
    private $address;
}
<?php
use Doctrine\ORM\Mapping as ORM;
use MonterHealth\ApiFilterBundle\Annotation\ApiFilter;
use MonterHealth\ApiFilterBundle\Filter\SearchFilter;

/** @ORM\Embeddable */
class Address
{
    /** @ORM\Column(type = "string") */
    private $street;

    /** @ORM\Column(type = "string") */
    private $postalCode;

    /** @ORM\Column(type = "string") */
    private $city;

    /** @ORM\Column(type = "string") */
    private $country;
}
<?php
namespace App\Controller;

use App\Repository\UserRepository;
use MonterHealth\ApiFilterBundle\MonterHealthApiFilter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class UserController extends AbstractController
{
    /**
     * @Route("users", name="get_users", methods={"GET"})
     * @param Request $request
     * @param UserRepository $repository
     * @param MonterHealthApiFilter $monterHealthApiFilter
     * @return JsonResponse
     * @throws \ReflectionException
     */
    public function getBooks(Request $request, UserRepository $repository, MonterHealthApiFilter $monterHealthApiFilter): JsonResponse
    {
        $queryBuilder = $repository->findAllQueryBuilder();
        $monterHealthApiFilter->addFilterConstraints($queryBuilder, $repository->getClassName(), $request->query);

        return new JsonResponse($queryBuilder->getQuery()->getArrayResult());
    }
}

now after everything it is in place we invoke the api and what we expect it i to obtain users filtered by address.city = "Rome"

curl -X 'GET' 'http://127.0.0.1:8080/users?address:city=Rome&limit=20&page=1'

what happens in reality it is that the filter it is simply ignored or confused with a join.

After some debug i wrote a solution that i will submit soon

Using attribute instead of annotation

Since PHP 8 support attribute, maybe we can consider to support attribute as well? I wonder will it clash with annotation?

#[ApiFilter(SearchFilter::class, properties: ["id"])]
class Product
{
   #[ApiFilter(SearchFilter::class)]
   private $id;
}

Hi, i have a question about OrderFilter annotation.

Hi, i would like to know what are the usage of this annotation (sorry because the docs lack of info about this):

 * @ApiFilter(OrderFilter::class, properties={
 *     "author": OrderFilter::ASCENDING,
 *     "pages": OrderFilter::DESCENDING,
 * })

If we need to provide a query like /books?order[asc]=author to make ascending or descending order, what's the point of using those annotation like above? Thanks.

Filtering on table that has no direct relationship by using join

For example:

We want to filter on properties in the component entity that is joined.

$queryBuilder
->select(['device', 'component'])
->from(Device::class, 'device')
->leftJoin(Component::class, 'component', Join::WITH, 'device.hostname = component.hostname')
;
$this->monterHealthApiFilter->addFilterConstraints($queryBuilder, Device::class, $request->query);
$this->monterHealthApiFilter->addFilterConstraints($queryBuilder, CmdbComponent::class, $request->query);

We defined the ApiFilters on the Component class like this:

/**
 * @var string
 *
 * @ORM\Column(name="organization", type="string", length=255, nullable=true)
 * @ApiFilter(SearchFilter::class)
 */
private $organization;

When adding this query param to the API call: /?component:organization=Test,
the filters are not applied. is there a way that we can use filters on a joined table?

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.