Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listKey argument to DoctrineListRepresentationFactory and DoctrineNestedListRepresentationFactory #10

Conversation

luca-rath
Copy link
Contributor

@luca-rath luca-rath commented Aug 28, 2022

Currently those classes only work properly, if the LIST_KEY and the RESOURCE_KEY are equal. If this is not the case, you would have to do something like the following, to make it work:

public function cgetAction(Request $request): Response
{
    $listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation(
        self::LIST_KEY, // Note that this argument is named $resourceKey
    );

    $listRepresentation = new PaginatedRepresentation(
        $listRepresentation->getData(),
        self::RESOURCE_KEY,
        $listRepresentation->getPage(),
        $listRepresentation->getLimit(),
        $listRepresentation->getTotal(),
    );

    return $this->handleView(
        $this->view($listRepresentation)
    );
}

With this pull request, the code can be simplified to the following:

public function cgetAction(Request $request): Response
{
    $listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation(
        self::RESOURCE_KEY,
        [],
        [],
        [],
        self::LIST_KEY,
    );

    return $this->handleView(
        $this->view($listRepresentation)
    );
}

@luca-rath luca-rath force-pushed the feature/doctrine-list-representation-factories-list-key branch from 262fe04 to 01a34b5 Compare November 7, 2022 13:36
@alexander-schranz alexander-schranz added the enhancement New feature or request label Nov 7, 2022
@alexander-schranz
Copy link
Member

We still should make sure that resource key and list keys are matching in our projects ;)

@alexander-schranz alexander-schranz merged commit 841392d into handcraftedinthealps:0.x Nov 7, 2022
@luca-rath
Copy link
Contributor Author

We still should make sure that resource key and list keys are matching in our projects ;)

Yes I agree, but there are edge cases where this is not possible. Recently we had a customer project, where a specific export list config was required, so there were two list configs for the same resource

@luca-rath luca-rath deleted the feature/doctrine-list-representation-factories-list-key branch November 7, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants