-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
732 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230911215906 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE shipment_budget (id BINARY(16) NOT NULL COMMENT \'(DC2Type:ulid)\', currency VARCHAR(3) NOT NULL, dtype VARCHAR(255) NOT NULL, price INT DEFAULT NULL, min_price INT DEFAULT NULL, max_price INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE shipment ADD budget_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:ulid)\''); | ||
$this->addSql('ALTER TABLE shipment ADD CONSTRAINT FK_2CB20DC36ABA6B8 FOREIGN KEY (budget_id) REFERENCES shipment_budget (id)'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_2CB20DC36ABA6B8 ON shipment (budget_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE shipment DROP FOREIGN KEY FK_2CB20DC36ABA6B8'); | ||
$this->addSql('DROP TABLE shipment_budget'); | ||
$this->addSql('DROP INDEX UNIQ_2CB20DC36ABA6B8 ON shipment'); | ||
$this->addSql('ALTER TABLE shipment DROP budget_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230911220220 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE shipment ADD updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', ADD created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE shipment DROP updated_at, DROP created_at'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230911234025 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE shipment ADD type VARCHAR(64) NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE shipment DROP type'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Entity\Shipment; | ||
|
||
use App\Repository\Shipment\ShipmentBudgetRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Bridge\Doctrine\Types\UlidType; | ||
use Symfony\Component\Uid\Ulid; | ||
use Overblog\GraphQLBundle\Annotation as GQL; | ||
use Overblog\GraphQLBundle\Resolver\TypeResolver; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
#[GQL\TypeInterface(resolveType:'value.resolveGQLType(typeResolver)')] | ||
#[ORM\InheritanceType("SINGLE_TABLE")] | ||
#[ORM\Entity(repositoryClass: ShipmentBudgetRepository::class)] | ||
abstract class ShipmentBudget | ||
{ | ||
#[GQL\Field(type: "Ulid")] | ||
#[ORM\Id] | ||
#[ORM\Column(type: UlidType::NAME, unique: true)] | ||
#[ORM\GeneratedValue(strategy: 'CUSTOM')] | ||
#[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')] | ||
private ?Ulid $id = null; | ||
|
||
#[GQL\Field()] | ||
#[ORM\Column(length: 3)] | ||
private ?string $currency = null; | ||
|
||
#[ORM\OneToOne(mappedBy: 'budget', cascade: ['persist', 'remove'])] | ||
private ?Shipment $shipment = null; | ||
|
||
public function getId(): ?Ulid | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getCurrency(): ?string | ||
{ | ||
return $this->currency; | ||
} | ||
|
||
public function setCurrency(string $currency): static | ||
{ | ||
$this->currency = $currency; | ||
|
||
return $this; | ||
} | ||
|
||
abstract function resolveGQLType( TypeResolver $typeResolver): Type; | ||
|
||
public function getShipment(): ?Shipment | ||
{ | ||
return $this->shipment; | ||
} | ||
|
||
public function setShipment(?Shipment $shipment): static | ||
{ | ||
// unset the owning side of the relation if necessary | ||
if ($shipment === null && $this->shipment !== null) { | ||
$this->shipment->setBudget(null); | ||
} | ||
|
||
// set the owning side of the relation if necessary | ||
if ($shipment !== null && $shipment->getBudget() !== $this) { | ||
$shipment->setBudget($this); | ||
} | ||
|
||
$this->shipment = $shipment; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Entity\Shipment; | ||
|
||
use App\Repository\Shipment\ShipmentFixedBudgetRepository; | ||
use GraphQL\Type\Definition\Type; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Overblog\GraphQLBundle\Annotation as GQL; | ||
use Overblog\GraphQLBundle\Resolver\TypeResolver; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
#[Assert\Expression("value.price is not null")] | ||
#[GQL\Type()] | ||
#[ORM\Entity(repositoryClass: ShipmentFixedBudgetRepository::class)] | ||
class ShipmentFixedBudget extends ShipmentBudget | ||
{ | ||
|
||
#[Assert\GreaterThan(0)] | ||
#[GQL\Field()] | ||
#[ORM\Column(nullable: true)] | ||
private ?int $price = null; | ||
|
||
public function getPrice(): ?int | ||
{ | ||
return $this->price; | ||
} | ||
|
||
public function setPrice(int $price): static | ||
{ | ||
$this->price = $price; | ||
|
||
return $this; | ||
} | ||
|
||
public function resolveGQLType(TypeResolver $typeResolver): Type{ | ||
return $typeResolver->resolve('ShipmentFixedBudget'); | ||
} | ||
} |
Oops, something went wrong.