Skip to content

Commit

Permalink
Save Shipment
Browse files Browse the repository at this point in the history
  • Loading branch information
nkamuo committed Sep 12, 2023
1 parent 255f33a commit 5da142d
Show file tree
Hide file tree
Showing 26 changed files with 732 additions and 13 deletions.
1 change: 1 addition & 0 deletions config/packages/lexik_jwt_authentication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ lexik_jwt_authentication:
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
allow_no_expiration: true
# token_ttl: 0
# token_ttl: 30000000
37 changes: 37 additions & 0 deletions migrations/Version20230911215906.php
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');
}
}
31 changes: 31 additions & 0 deletions migrations/Version20230911220220.php
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');
}
}
31 changes: 31 additions & 0 deletions migrations/Version20230911234025.php
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');
}
}
16 changes: 15 additions & 1 deletion src/Entity/Account/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
private ?Ulid $id = null;

#[GQL\Field()]
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;

/**
* @var string[]
*/
#[GQL\Field()]
#[ORM\Column]
private array $roles = [];

Expand All @@ -40,21 +45,26 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column]
private ?string $password = null;

#[GQL\Field()]
#[ORM\Column(length: 64)]
private ?string $firstName = null;

#[GQL\Field()]
#[ORM\Column(length: 64)]
private ?string $lastName = null;

#[GQL\Field()]
#[ORM\Column(length: 64, nullable: true)]
private ?string $phone = null;

#[GQL\Field()]
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
private bool $isVerified = false;

#[ORM\OneToMany(mappedBy: 'owner', targetEntity: UserAddress::class, orphanRemoval: true)]
private Collection $addressess;

#[GQL\Field()]
#[ORM\OneToOne(mappedBy: 'userAccount', cascade: ['persist', 'remove'])]
private ?Driver $driver = null;

Expand Down Expand Up @@ -99,6 +109,10 @@ public function getRoles(): array
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';

if($this->driver != null){
$roles[] = 'ROLE_DRIVER';
}

return array_unique($roles);
}

Expand Down
78 changes: 73 additions & 5 deletions src/Entity/Shipment/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,74 @@ class Shipment
#[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
private ?Ulid $id = null;

#[GQL\Field()]
#[ORM\Column(length: 64, enumType: ShipmentType::class)]
private ?ShipmentType $type = null;

#[GQL\Field()]
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?User $owner = null;

#[GQL\Field()]
#[ORM\ManyToOne]
#[ORM\ManyToOne(cascade: ['persist',])]
private ?UserAddress $billingAddress = null;

#[GQL\Field()]
#[ORM\ManyToOne]
#[ORM\ManyToOne(cascade: ['persist',])]
private ?UserAddress $originAddress = null;

#[GQL\Field()]
#[ORM\ManyToOne]
#[ORM\ManyToOne(cascade: ['persist',])]
private ?UserAddress $destinationAddress = null;

#[GQL\Field(type:'[ShipmentItem!]!')]
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: ShipmentItem::class, orphanRemoval: true)]
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: ShipmentItem::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $items;

#[GQL\Field(type:'[ShipmentDriverBid!]!')]
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: ShipmentDriverBid::class, orphanRemoval: true)]
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: ShipmentDriverBid::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $bids;

#[GQL\Field()]
#[ORM\OneToOne(inversedBy: 'shipment', cascade: ['persist', 'remove'])]
private ?ShipmentBudget $budget = null;

#[GQL\Field(type: "DateTime")]
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;

#[GQL\Field(type: "DateTime")]
#[ORM\Column()]
private ?\DateTimeImmutable $createdAt = null;


public function __construct(?Ulid $id = null)
{
$this->id = $id;
$this->items = new ArrayCollection();
$this->bids = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
}

public function getId(): ?Ulid
{
return $this->id;
}


public function getType(): ?ShipmentType
{
return $this->type;
}

public function setType(ShipmentType $type): static
{
$this->type = $type;

return $this;
}

public function getOwner(): ?User
{
return $this->owner;
Expand Down Expand Up @@ -167,4 +198,41 @@ public function removeBid(ShipmentDriverBid $bid): static

return $this;
}

public function getBudget(): ?ShipmentBudget
{
return $this->budget;
}

public function setBudget(?ShipmentBudget $budget): static
{
$this->budget = $budget;

return $this;
}

public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}

public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
{
$this->updatedAt = $updatedAt;

return $this;
}

public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}

public function setCreatedAt(?\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;

return $this;
}

}
72 changes: 72 additions & 0 deletions src/Entity/Shipment/ShipmentBudget.php
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;
}
}
38 changes: 38 additions & 0 deletions src/Entity/Shipment/ShipmentFixedBudget.php
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');
}
}
Loading

0 comments on commit 5da142d

Please sign in to comment.