feat: better data wf

This commit is contained in:
2024-01-18 16:41:03 +01:00
parent 9bd3b5efff
commit 1a3cf1c2e0
22 changed files with 186 additions and 77 deletions

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCode;
interface CacheableQRCodeGeneratorInterface extends QRCodeGeneratorInterface
{

View File

@@ -3,9 +3,8 @@ declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCode;
use Exception;
use Psr\Cache\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Service\DTO;
use App\Entity\DTO\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCodeMoney;
use App\Entity\DTO\QRCode\QRCodePaymentIdentification;
use App\Entity\DTO\QRCode\QRCodeQROptions;
use Symfony\Component\Validator\Validator\ValidatorInterface;
final readonly class QRCodeEntityConverter
{
public function __construct(private ValidatorInterface $validator) {
}
public function convert(\App\Entity\Input\QRCode\QRCode $code): QRCode {
if (count($this->validator->validate($code)) !== 0) {
throw new \InvalidArgumentException("QRCode entity is not valid");
}
return new QRCode(
$code->getIban() ?? throw new \InvalidArgumentException("iban not set"),
\DateTimeImmutable::createFromMutable($code->getDueDate() ?? throw new \InvalidArgumentException("due date not set")),
$code->getMessage() ?? throw new \InvalidArgumentException("message not set"),
$this->convertMoney($code->getMoney() ?? throw new \InvalidArgumentException("money not set")),
$this->convertCodeOptions($code->getCodeQROptions() ?? throw new \InvalidArgumentException("codeQROptions not set")),
$this->convertIdentification($code->getPaymentIdentification())
);
}
protected function convertMoney(\App\Entity\Input\QRCode\QRCodeMoney $money): QRCodeMoney
{
return new QRCodeMoney(
$money->getAmount() ?? throw new \InvalidArgumentException("amount not set"),
$money->getCurrency() ?? throw new \InvalidArgumentException("currency not set")
);
}
protected function convertCodeOptions(\App\Entity\Input\QRCode\QRCodeQROptions $options): QRCodeQROptions
{
return new QRCodeQROptions(
$options->getScale(),
$options->getMargin()
);
}
protected function convertIdentification(?\App\Entity\Input\QRCode\QRCodePaymentIdentification $ident): ?QRCodePaymentIdentification {
return match ($ident) {
null => null,
default => new QRCodePaymentIdentification(
$ident->getVariableSymbol(),
$ident->getSpecificSymbol(),
$ident->getConstantSymbol()
)
};
}
}

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCode;
use App\Service\Exception\QRCodeGeneratorException;
interface QRCodeGeneratorInterface

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCodeQROptions;
use App\Entity\Input\QRCode\QRCodeQROptions;
readonly final class QRCodeQROptionsDefaultProvider implements QRCodeQROptionsProviderInterface {
const DEFAULT_SCALE = 8;

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCodeQROptions;
use App\Entity\Input\QRCode\QRCodeQROptions;
interface QRCodeQROptionsProviderInterface {
public function getDefault(): QRCodeQROptions;

View File

@@ -3,10 +3,10 @@ declare(strict_types=1);
namespace App\Service\Remote\Edge;
use App\Entity\QRCode\QRCode;
use App\Entity\QRCode\QRCodeMoney;
use App\Entity\QRCode\QRCodePaymentIdentification;
use App\Entity\QRCode\QRCodeQROptions;
use App\Entity\DTO\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCodeMoney;
use App\Entity\DTO\QRCode\QRCodePaymentIdentification;
use App\Entity\DTO\QRCode\QRCodeQROptions;
use App\Entity\Remote\Usetreno\Edge\EdgeQRCode;
use App\Entity\Remote\Usetreno\Edge\EdgeQRCodeMoney;
use App\Entity\Remote\Usetreno\Edge\EdgeQRCodePaymentIdentification;
@@ -19,28 +19,28 @@ class QRCodeEntityConverter
public function convert(QRCode $code): EdgeQRCode {
return new EdgeQRCode(
$code->getIban() ?? throw new MissingParameterException("iban not set"),
$code->getDueDate() ? $code->getDueDate()->format('Y-m-d') : throw new MissingParameterException("due date not set"),
$code->getMessage() ?? throw new MissingParameterException("message not set"),
$this->convertMoney($code->getMoney() ?? throw new MissingParameterException("money not set")),
$this->convertCodeOptions($code->getCodeQROptions() ?? throw new MissingParameterException("codeQROptions not set")),
$this->convertIdentification($code->getPaymentIdentification())
$code->iban,
$code->dueDate->format('Y-m-d'),
$code->message,
$this->convertMoney($code->money),
$this->convertCodeOptions($code->qrOptions),
$this->convertIdentification($code->paymentIdentification)
);
}
protected function convertMoney(QRCodeMoney $money): EdgeQRCodeMoney
{
return new EdgeQRCodeMoney(
$money->getAmount() ?? throw new MissingParameterException("amount not set"),
$money->getCurrency() ?? throw new MissingParameterException("currency not set")
$money->amount,
$money->currency
);
}
protected function convertCodeOptions(QRCodeQROptions $options): EdgeQRCodeQROptions
{
return new EdgeQRCodeQROptions(
$options->getScale(),
$options->getMargin()
$options->scale,
$options->margin
);
}
@@ -53,9 +53,9 @@ class QRCodeEntityConverter
"0"
),
default => new EdgeQRCodePaymentIdentification(
$ident->getVariableSymbol() ?? "0",
$ident->getSpecificSymbol() ?? "0",
$ident->getConstantSymbol() ?? "0"
$ident->variableSymbol ?? "0",
$ident->specificSymbol ?? "0",
$ident->constantSymbol ?? "0"
)
};
}

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Service\Remote;
use App\Entity\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCode;
use App\Service\CacheableQRCodeGeneratorInterface;
use App\Service\Remote\Edge\QRCodeEntityConverter;
use App\Service\Remote\Exception\UsetrenoQRCodeException;

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Service;
use App\Entity\QRCode\QRCode;
use App\Entity\DTO\QRCode\QRCode;
readonly final class StubQRCodeGenerator implements QRCodeGeneratorInterface
{