What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

can you return `void` from a GatewayController ? or rather, do we have to create a transfer object e

UKGT7RC7P
UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet
edited April 2020 in Help

can you return void from a GatewayController ? or rather, do we have to create a transfer object even if the action is a notification?

Β«1

Comments

  • UQS4LDZU7
    UQS4LDZU7 Posts: 182 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited April 2020

    Had this issue as well. To make it short - you ALWAYS need a transfer. If you dont have any properties to pass, just pass an empty object. That should do the job.

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    that depends on ZedRequestClient

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    by default it returns Transfer object from last response

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    an empty transfer you mean?

  • UQS4LDZU7
    UQS4LDZU7 Posts: 182 πŸ§‘πŸ»β€πŸš€ - Cadet

    @UKGT7RC7P Yes.

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet
    \Spryker\Shared\ZedRequest\Client\AbstractHttpClient::getTransferFromResponse()
    
  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet
    $data = json_decode(trim($response->getBody()), true);
            if (!$data || !is_array($data)) {
                throw new InvalidZedResponseException('Invalid JSON', $response, $request->getUri());
            }
    
  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    hm, so you could override the ZedRequestClient

  • Ievgen Varava
    Ievgen Varava Sprykee Posts: 154 πŸ§‘πŸ»β€πŸš€ - Cadet

    you have to if you really need to return void from gateway controller

  • UQS4LDZU7
    UQS4LDZU7 Posts: 182 πŸ§‘πŸ»β€πŸš€ - Cadet

    @UKGT7RC7P Never came to this idea, but Ievgen knows for sure better.

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    well, often i'd like to pass / return non-transfer objects

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    (especially passing)

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    seems I often do BlahRequestTransfer and BlahResponseTransfer

  • UQS4LDZU7
    UQS4LDZU7 Posts: 182 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited April 2020

    @UKGT7RC7P Passing non-transfer objects (i.e. arrays etc) between app layers breaks the Spryker conventions afaik.

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    of course πŸ™‚

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    the problem is you end up creating a transfer object per request if they have different args

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    or, worse, you use the same transfer object for all of them and have no API at all

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    would be so much nicer to just pass arguments

  • UQS4LDZU7
    UQS4LDZU7 Posts: 182 πŸ§‘πŸ»β€πŸš€ - Cadet

    I agree, it somehow hurts. But, on the other hand, you are welcome to create unlimited amount of TOs πŸ™‚

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    πŸ‘€

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    Creating a transfer is a very small overhead, it would be possible to remove this requirement but it takes a lot of overriding on the project level. In my opinion it is just not worth it.

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    And by convention you should be sending and receiving a business object ... just saying

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    I know that's the convention, but the "business" objects are transfer objects where everything is nullable

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    you can always return true if action is successful

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    can you? πŸ€”

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    wrapped in a transfer of course

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    BooleanTransfer.php

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    I usually make a {ActionName}ResponseTransfer

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    and then if I need to actually return something I can add stuff

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    and I have property isSuccess in it