Skip to content

Conversation

@a-olmedo
Copy link
Contributor

https://wkdauto.atlassian.net/browse/PUR2-1718

This PR allows us to create DTOs using query parameters for GET endpoints.

For example, for the given URL:
GET /v1/vat/vat-partitions/country/ES?localeCode=es-ES

service-api-endpoints-bundle:

endpoints:
  - requestClass:  'WKDA\DTO\VatService\VatService\Request\GetVatPartitionCollectionByCountry'
    method:        'GET'
    path:          '/v1/vat/vat-partitions/country/{country}'
    responseClass: 'WKDA\DTO\VatService\VatService\Response\VatPartitionCollection'

DTO:

<?php

declare(strict_types=1);

namespace WKDA\DTO\VatService\VatService\Request;

use Auto1\ServiceAPIRequest\ServiceRequestInterface;

/**
 * Class GetVatPartitionCollectionByCountry
 */
class GetVatPartitionCollectionByCountry implements ServiceRequestInterface
{
    /**
     * @var string
     */
    private $country;

    /**
     * @var string|null
     */
    private $localeCode;

    /**
     * @return string
     */
    public function getCountry(): string
    {
        return $this->country;
    }

    /**
     * @param string $country
     * @return $this
     */
    public function setCountry(string $country): self
    {
        $this->country = $country;

        return $this;
    }

    public function getLocaleCode(): ?string
    {
        return $this->localeCode;
    }

    public function setLocaleCode(?string $localeCode): self
    {
        $this->localeCode = $localeCode;

        return $this;
    }
}

We can use the localeCode parameter from the DTO:

    public function getByCountryAction(GetVatPartitionCollectionByCountry $request): JsonResponse
    {
        return new JsonResponse(
            $this->serializer->serialize(
                $this->vatPartitionService->getListByCountry($request->getCountry(), $request->getLocaleCode()),
                'json'
            ),
            Response::HTTP_OK,
            [],
            true
        );
    }

@diego1auto diego1auto merged commit 84bcb1b into auto1-oss:master Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants