Skip to content

Commit

Permalink
Rename ExchangeRate into ExchangeRateLive
Browse files Browse the repository at this point in the history
  • Loading branch information
coldic3 committed Jul 23, 2023
1 parent 8b74b8d commit a708670
Show file tree
Hide file tree
Showing 65 changed files with 490 additions and 461 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# language: pl

@exchange_rate
@exchange_rate_live
Potrzeba biznesowa: Zmiana kursu wymiany
W celu korzystania śledzenia kursu wymiany aktywów
Jako użytkownik
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# language: pl

@exchange_rate
@exchange_rate_live
Potrzeba biznesowa: Tworzenie kursu wymiany
W celu posiadania informacji o kursie wymiany między dwoma aktywami
Jako użytkownik
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# language: pl

@exchange_rate
@exchange_rate_live
Potrzeba biznesowa: Usuwanie kursów wymiany
W celu posiadania tylko potrzebnych kursów wymiany
Jako użytkownik
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# language: pl

@exchange_rate
@exchange_rate_live
Potrzeba biznesowa: Wyświetlanie kursów wymiany
W celu śledzenia zmiany kursów dla wybranych aktywów
Jako użytkownik
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
include:
- 'assets.yaml'

Panda\Exchange\Domain\Model\ExchangeRate:
exchange_rate_acme_1:
Panda\Exchange\Domain\Model\ExchangeRateLive:
exchange_rate_live_acme_1:
__construct: ['@asset_acme->ticker', '@asset_1->ticker', '<randomFloat(2, 0, 3)>']
createdAt: <(new DateTimeImmutable())>
updatedAt: <(new DateTimeImmutable())>
exchange_rate_acme_2:
exchange_rate_live_acme_2:
__construct: ['@asset_acme->ticker', '@asset_2->ticker', '<randomFloat(2, 0, 3)>']
createdAt: <(new DateTimeImmutable())>
updatedAt: <(new DateTimeImmutable())>
exchange_rate_acme_3:
exchange_rate_live_acme_3:
__construct: ['@asset_acme->ticker', '@asset_3->ticker', '<randomFloat(2, 0, 3)>']
createdAt: <(new DateTimeImmutable())>
updatedAt: <(new DateTimeImmutable())>
exchange_rate_acme_4:
exchange_rate_live_acme_4:
__construct: ['@asset_acme->ticker', '@asset_4->ticker', '<randomFloat(2, 0, 3)>']
createdAt: <(new DateTimeImmutable())>
updatedAt: <(new DateTimeImmutable())>
29 changes: 29 additions & 0 deletions migrations/Version20230723222438.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230723222438 extends AbstractMigration
{
public function getDescription(): string
{
return 'Rename ExchangeRate into ExchangeRateLive';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE panda_exchange_rate RENAME TO panda_exchange_rate_live');
$this->addSql('ALTER INDEX uniq_1992c039d58bbb05589c0d1c RENAME TO UNIQ_B1C1ADC316A390FF447BA6D5');

}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE panda_exchange_rate_live RENAME TO panda_exchange_rate');
$this->addSql('ALTER INDEX uniq_b1c1adc316a390ff447ba6d5 RENAME TO uniq_1992c039d58bbb05589c0d1c');
}
}
22 changes: 11 additions & 11 deletions responses/api/exchange_rate/get/collection.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"@context": "/contexts/ExchangeRate",
"@id": "/exchange_rates",
"@context": "/contexts/ExchangeRateLive",
"@id": "/exchange_rate_lives",
"@type": "hydra:Collection",
"hydra:totalItems": 4,
"hydra:member": [
{
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK1",
"rate": "@number@",
"createdAt": "@datetime@",
"updatedAt": "@datetime@"
},
{
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK2",
"rate": "@number@",
"createdAt": "@datetime@",
"updatedAt": "@datetime@"
},
{
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK3",
"rate": "@number@",
"createdAt": "@datetime@",
"updatedAt": "@datetime@"
},
{
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK4",
"rate": "@number@",
Expand All @@ -43,7 +43,7 @@
],
"hydra:search": {
"@type": "hydra:IriTemplate",
"hydra:template": "/exchange_rates{?baseTicker,quoteTicker}",
"hydra:template": "/exchange_rate_lives{?baseTicker,quoteTicker}",
"hydra:variableRepresentation": "BasicRepresentation",
"hydra:mapping": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"@context": "/contexts/ExchangeRate",
"@id": "/exchange_rates",
"@context": "/contexts/ExchangeRateLive",
"@id": "/exchange_rate_lives",
"@type": "hydra:Collection",
"hydra:totalItems": 1,
"hydra:member": [
{
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK1",
"rate": "@number@",
Expand All @@ -15,12 +15,12 @@
}
],
"hydra:view": {
"@id": "/exchange_rates?baseTicker=ACM&quoteTicker=TCK1",
"@id": "/exchange_rate_lives?baseTicker=ACM&quoteTicker=TCK1",
"@type": "hydra:PartialCollectionView"
},
"hydra:search": {
"@type": "hydra:IriTemplate",
"hydra:template": "/exchange_rates{?baseTicker,quoteTicker}",
"hydra:template": "/exchange_rate_lives{?baseTicker,quoteTicker}",
"hydra:variableRepresentation": "BasicRepresentation",
"hydra:mapping": [
{
Expand Down
6 changes: 3 additions & 3 deletions responses/api/exchange_rate/get/item.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"@context": "/contexts/ExchangeRate",
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@context": "/contexts/ExchangeRateLive",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK1",
"rate": "@number@",
Expand Down
6 changes: 3 additions & 3 deletions responses/api/exchange_rate/patch/valid.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"@context": "/contexts/ExchangeRate",
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@context": "/contexts/ExchangeRateLive",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK1",
"rate": "@number@",
Expand Down
6 changes: 3 additions & 3 deletions responses/api/exchange_rate/post/valid.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"@context": "/contexts/ExchangeRate",
"@id": "/exchange_rates/@uuid@",
"@type": "ExchangeRate",
"@context": "/contexts/ExchangeRateLive",
"@id": "/exchange_rate_lives/@uuid@",
"@type": "ExchangeRateLive",
"baseTicker": "ACM",
"quoteTicker": "TCK1",
"rate": "@number@",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Panda\Exchange\Application\Command\ExchangeRate;
namespace Panda\Exchange\Application\Command\ExchangeRateLive;

use Panda\Core\Application\Command\CommandInterface;

final readonly class CreateExchangeRateCommand implements CommandInterface
final readonly class CreateExchangeRateLiveCommand implements CommandInterface
{
public function __construct(
public string $baseTicker,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Panda\Exchange\Application\Command\ExchangeRateLive;

use ApiPlatform\Validator\ValidatorInterface;
use Panda\Core\Application\Command\CommandHandlerInterface;
use Panda\Core\Application\Event\EventBusInterface;
use Panda\Exchange\Domain\Event\ExchangeRateLiveCreatedEvent;
use Panda\Exchange\Domain\Event\ReversedExchangeLiveRateCreatedEvent;
use Panda\Exchange\Domain\Factory\ExchangeRateLiveFactoryInterface;
use Panda\Exchange\Domain\Model\ExchangeRateLiveInterface;
use Panda\Exchange\Domain\Repository\ExchangeRateLiveRepositoryInterface;

final readonly class CreateExchangeRateLiveCommandHandler implements CommandHandlerInterface
{
public function __construct(
private ExchangeRateLiveRepositoryInterface $exchangeRateRepository,
private ExchangeRateLiveFactoryInterface $exchangeRateFactory,
private EventBusInterface $eventBus,
private ValidatorInterface $validator,
) {
}

public function __invoke(CreateExchangeRateLiveCommand|CreateReversedExchangeRateLiveCommand $command): ExchangeRateLiveInterface
{
$exchangeRate = $this->exchangeRateFactory->create($command->baseTicker, $command->quoteTicker, $command->rate);

$this->validator->validate($exchangeRate, ['groups' => ['panda:create']]);

$this->exchangeRateRepository->save($exchangeRate);

switch (get_class($command)) {
case CreateExchangeRateLiveCommand::class:
$this->eventBus->dispatch(new ExchangeRateLiveCreatedEvent($exchangeRate->getId()));
break;
case CreateReversedExchangeRateLiveCommand::class:
$this->eventBus->dispatch(new ReversedExchangeLiveRateCreatedEvent($exchangeRate->getId()));
break;
}

return $exchangeRate;
}
}
Loading

0 comments on commit a708670

Please sign in to comment.