Skip to content

Commit

Permalink
Updated required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire committed Dec 27, 2023
1 parent b4600e0 commit 53c05d8
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Api/Monetization/Controller/AcceptedRatePlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public function getPaginatedAcceptedRatePlanList(int $limit = null, int $page =
return $this->getAcceptedRatePlans($query_params);
}

/**
* {@inheritdoc}
*/
public function getAllEligibleRatePlans(): array
{
return $this->getEligibleRatePlan();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -195,4 +203,31 @@ private function getAcceptedRatePlans(array $query_params = []): array

return $entities;
}

/**
* Helper function for listing eligible rate plans.
*
* @param array $query_params
* Additional query parameters.
*
* @return \Apigee\Edge\Api\Monetization\Entity\AcceptedRatePlanInterface[]
*
* @psalm-suppress PossiblyNullArrayOffset - id() does not return null here.
*/
private function getEligibleRatePlan(): array
{
$entities = [];

foreach ($this->getRawList($this->getEligibleRatePlanEndpoint()) as $item) {
/** @var \Apigee\Edge\Entity\EntityInterface $tmp */
$tmp = $this->getEntitySerializer()->denormalize(
$item,
AcceptedRatePlanInterface::class,
'json'
);
$entities[$tmp->id()] = $tmp;
}

return $entities;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ interface AcceptedRatePlanControllerInterface extends EntityControllerInterface,
*/
public function getAllAcceptedRatePlans(): array;

/**
* Gets all eligible rate plans.
*
* @return \Apigee\Edge\Api\Monetization\Entity\AcceptedRatePlanInterface[]
*/
public function getAllEligibleRatePlans(): array;

/**
* Gets accepted rate plans in the provided range.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Apigee\Edge\Api\Monetization\Denormalizer;

use Apigee\Edge\Api\Monetization\Entity\CompanyEligibleRatePlan;
use Apigee\Edge\Api\Monetization\NameConverter\CompanyEligibleRatePlanNameConverter;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;

class CompanyEligibleRatePlanDenormalizer extends AcceptedRatePlanDenormalizer
{
/**
* Fully qualified class name of the company accepted rate plan entity.
*
* @var string
*/
protected $companyEligibleRatePlanClass = CompanyEligibleRatePlan::class;

/**
* CompanyEligibleRatePlanDenormalizer constructor.
*
* @param \Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface|null $classMetadataFactory
* @param \Symfony\Component\Serializer\NameConverter\NameConverterInterface|null $nameConverter
* @param \Symfony\Component\PropertyAccess\PropertyAccessorInterface|null $propertyAccessor
* @param \Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface|null $propertyTypeExtractor
*/
public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory = null, ?NameConverterInterface $nameConverter = null, ?PropertyAccessorInterface $propertyAccessor = null, ?PropertyTypeExtractorInterface $propertyTypeExtractor = null)
{
$nameConverter = $nameConverter ?? new CompanyEligibleRatePlanNameConverter();
parent::__construct($classMetadataFactory, $nameConverter, $propertyAccessor, $propertyTypeExtractor);
}

/**
* {@inheritdoc}
*/
public function denormalize($data, $type, $format = null, array $context = [])
{
return parent::denormalize($data, $this->companyEligibleRatePlanClass, $format, $context);
}

/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null)
{
if (parent::supportsDenormalization($data, $type, $format)) {
return $data->developer->isCompany;
}

return false;
}
}
13 changes: 13 additions & 0 deletions src/Api/Monetization/Entity/CompanyEligibleRatePlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Apigee\Edge\Api\Monetization\Entity;

use Apigee\Edge\Api\Monetization\Entity\Property\CompanyPropertyAwareTrait;

/**
* Represents an accepted rate plan by a company.
*/
class CompanyEligibleRatePlan extends AcceptedRatePlan implements CompanyEligibleRatePlanInterface
{
use CompanyPropertyAwareTrait;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Apigee\Edge\Api\Monetization\Entity;

use Apigee\Edge\Api\Monetization\Entity\Property\CompanyPropertyInterface;

interface CompanyEligibleRatePlanInterface extends AcceptedRatePlanInterface, CompanyPropertyInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Apigee\Edge\Api\Monetization\NameConverter;

use Symfony\Component\Serializer\NameConverter\NameConverterInterface;

/**
* Converts "developer" to "company" on those accepted rate plans that
* belongs to a company. This is only used in the
* CompanyEligibleRatePlanController.
*
* @see \Apigee\Edge\Api\Monetization\Entity\CompanyEligibleRatePlan
*/
class CompanyEligibleRatePlanNameConverter extends NameConverterBase implements NameConverterInterface
{
/**
* {@inheritdoc}
*/
protected function getExternalToLocalMapping(): array
{
return [
'developer' => 'company',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Apigee\Edge\Api\Monetization\Normalizer;

use Apigee\Edge\Api\Monetization\Entity\CompanyEligibleRatePlanInterface;
use Apigee\Edge\Api\Monetization\NameConverter\CompanyEligibleRatePlanNameConverter;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;

class CompanyEligibleRatePlanNormalizer extends AcceptedRatePlanNormalizer
{
/**
* CompanyEligibleRatePlanNormalizer constructor.
*
* @param \Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface|null $classMetadataFactory
* @param \Symfony\Component\Serializer\NameConverter\NameConverterInterface|null $nameConverter
* @param \Symfony\Component\PropertyAccess\PropertyAccessorInterface|null $propertyAccessor
* @param \Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface|null $propertyTypeExtractor
*/
public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory = null, ?NameConverterInterface $nameConverter = null, ?PropertyAccessorInterface $propertyAccessor = null, ?PropertyTypeExtractorInterface $propertyTypeExtractor = null)
{
$nameConverter = $nameConverter ?? new CompanyEligibleRatePlanNameConverter();
parent::__construct($classMetadataFactory, $nameConverter, $propertyAccessor, $propertyTypeExtractor);
}

/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
{
return $data instanceof CompanyEligibleRatePlanInterface;
}
}

0 comments on commit 53c05d8

Please sign in to comment.