limoncello-php / app

Quick start JSON API application
MIT License
83 stars 7 forks source link

FluteSettings static::KEY_RELATIONSHIP_PAGING_SIZE does not reflect in the JsonApi #27

Closed dreamsbond closed 7 years ago

dreamsbond commented 7 years ago

@neomerx I found the captioned does not reflect in the JsonApi

neomerx commented 7 years ago

I can look closer this weekend.

dreamsbond commented 7 years ago

in the meantime, i think is it possible to make MAX_LIMIT_SIZE accessible to the FluteSetting?

neomerx commented 7 years ago

@dreamsbond I added the following line

        $settings[static::KEY_RELATIONSHIP_PAGING_SIZE] = 10;

here and got 10 records here

For me it seems to work. Where do you have the issue?

dreamsbond commented 7 years ago

@neomerx i do the same, it turns out that the static::KEY_RELATIONSHIP_PAGING_SIZE in config folder does not override the DEFAULT_LIMIT_SIZE of 20 in pagination strategy

dreamsbond commented 7 years ago

static::KEY_RELATIONSHIP_PAGING_SIZE applies to the

    public function __construct(int $defaultPageLimit = self::DEFAULT_LIMIT_SIZE)
    {
        $this->defaultPageLimit = $defaultPageLimit;
    }

while without changing the MAX_LIMIT_SIZE in PaginationStrategy

class PaginationStrategy implements PaginationStrategyInterface
{
    /** Paging constant */
    const DEFAULT_LIMIT_SIZE = 20;

    /** Paging constant */
    const MAX_LIMIT_SIZE = 100;

i found no effect on having page size to, say a 10000 to return the whole collection

neomerx commented 7 years ago

I found an issue with selecting min/max for page size. Can you try it with updated strategy?

neomerx commented 7 years ago

@dreamsbond would appreciate your feedback

dreamsbond commented 7 years ago

@neomerx sorry for late reply, feel unwell these days. will try it out and get you back very soon.

dreamsbond commented 7 years ago

@neomerx the static::KEY_RELATIONSHIP_PAGING_SIZE does finally reflect properly.

but another question is that, the MAX_LIMIT_SIZE of 100 was not accessible via FluteSettings

it only limits to a max size of 100 records to return no matter how i change the value of static::KEY_RELATIONSHIP_PAGING_SIZE;

besides, for relationships like .../user/1/relationships/posts. is it capable to do the same way specifying the size of records return?

dreamsbond commented 7 years ago

or is it capable to make an default global options for assigning the numbers of records return?

neomerx commented 7 years ago

@dreamsbond nice idea to add MAX_LIMIT_SIZE as a setting

neomerx commented 7 years ago

added to develop branch. Will be released today/tomorrow.

neomerx commented 7 years ago

merged to master

dreamsbond commented 5 years ago

Hi, I found the static::KEY_RELATIONSHIP_PAGING_SIZE in flutesetting is not longer available. The settings of DEFAULT_PAGE_SIZE and DEFAULT_MAX_PAGE_SIZE does not applies to relationship links and resources.

neomerx commented 5 years ago

Hi, I found the static::KEY_RELATIONSHIP_PAGING_SIZE in flutesetting is not longer available.

I guess, your question is about how to manage to load data in relationships. The library will ask the container for RelationshipPaginationStrategyInterface and then getParameters to have database offset and limit. By default, it returns default values 0 for offset and DEFAULT_PAGE_SIZE for the limit. You can put a custom implementation of the interface to the container.

The settings of DEFAULT_PAGE_SIZE and DEFAULT_MAX_PAGE_SIZE does not applies to relationship links and resources.

I think you are asking about customizing RelationshipPaginationStrategyInterface behaviour (see above).

dreamsbond commented 5 years ago

Do you mean i need to implement RelationshipPaginationStrategyInterface in Container folder?

neomerx commented 5 years ago

Sorry for late reply. Yes, you will need to implement the interface that suits your custom requirements. Here is the template

<?php declare(strict_types=1);

namespace App\Container;

use Limoncello\Contracts\Application\ContainerConfiguratorInterface;
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
use Limoncello\Flute\Contracts\Api\RelationshipPaginationStrategyInterface;

/**
 * @package App\Container
 */
class PaginationConfigurator implements ContainerConfiguratorInterface
{
    /** @var callable */
    const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME];

    /**
     * @inheritdoc
     */
    public static function configureContainer(LimoncelloContainerInterface $container): void
    {
        $container[RelationshipPaginationStrategyInterface::class] = new class implements RelationshipPaginationStrategyInterface
        {
            /**
             * @param string $rootClass
             * @param string $class
             * @param string $path
             * @param string $relationshipName
             *
             * @return array [$offset, $limit]
             */
            public function getParameters(string $rootClass, string $class, string $path, string $relationshipName): array
            {
                // TODO: Implement getParameters() method.
            }
        };
    }
}
dreamsbond commented 5 years ago

@neomerx. It is better than do it at each getPageLimitRule() in ReadQuery, thanks @neomerx !