feat : Expedition dev back-end WIP
This commit is contained in:
@@ -4,11 +4,29 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'customer')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
requirements: ['id' => '\d+'],
|
||||
normalizationContext: ['groups' => ['customer:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['customer:read']],
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
class Customer
|
||||
{
|
||||
#[ORM\Id]
|
||||
@@ -18,26 +36,25 @@ class Customer
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['shipment:read', 'shipment:write', 'customer:read', 'customer:write'])]
|
||||
private ?string $customer_label = null;
|
||||
#[Groups(['customer:read', 'shipment:read'])]
|
||||
private ?string $label = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['shipment:read', 'shipment:write', 'customer:read', 'customer:write'])]
|
||||
private ?string $customer_code = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'customers')]
|
||||
#[Groups(['shipment:read', 'shipment:write', 'customer:read', 'customer:write'])]
|
||||
private ?Address $id_adress = null;
|
||||
#[Groups(['customer:read', 'shipment:read'])]
|
||||
private ?string $code = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Shipment>
|
||||
* @var Collection<int, Address>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Shipment::class, mappedBy: 'id_customer')]
|
||||
private Collection $shipments;
|
||||
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'customers')]
|
||||
#[ORM\JoinTable(name: 'customer_address')]
|
||||
#[Groups(['customer:read'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private Collection $addresses;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->shipments = new ArrayCollection();
|
||||
$this->addresses = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -45,69 +62,33 @@ class Customer
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCustomerLabel(): ?string
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->customer_label;
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setCustomerLabel(string $customer_label): static
|
||||
public function setLabel(?string $label): void
|
||||
{
|
||||
$this->customer_label = $customer_label;
|
||||
|
||||
return $this;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function getCustomerCode(): ?string
|
||||
public function getCode(): ?string
|
||||
{
|
||||
return $this->customer_code;
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCustomerCode(string $customer_code): static
|
||||
public function setCode(?string $code): void
|
||||
{
|
||||
$this->customer_code = $customer_code;
|
||||
|
||||
return $this;
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
public function getIdAdress(): ?Address
|
||||
public function getAddresses(): Collection
|
||||
{
|
||||
return $this->id_adress;
|
||||
return $this->addresses;
|
||||
}
|
||||
|
||||
public function setIdAdress(?Address $id_adress): static
|
||||
public function setAddresses(Collection $addresses): void
|
||||
{
|
||||
$this->id_adress = $id_adress;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Shipment>
|
||||
*/
|
||||
public function getShipments(): Collection
|
||||
{
|
||||
return $this->shipments;
|
||||
}
|
||||
|
||||
public function addShipment(Shipment $shipment): static
|
||||
{
|
||||
if (!$this->shipments->contains($shipment)) {
|
||||
$this->shipments->add($shipment);
|
||||
$shipment->setIdCustomer($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeShipment(Shipment $shipment): static
|
||||
{
|
||||
if ($this->shipments->removeElement($shipment)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($shipment->getIdCustomer() === $this) {
|
||||
$shipment->setIdCustomer(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
$this->addresses = $addresses;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user