85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'carrier')]
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(
|
|
requirements: ['id' => '\d+'],
|
|
normalizationContext: ['groups' => ['carrier:read']],
|
|
),
|
|
new GetCollection(
|
|
normalizationContext: ['groups' => ['carrier:read']],
|
|
),
|
|
new Post(
|
|
normalizationContext: ['groups' => ['carrier:read']],
|
|
denormalizationContext: ['groups' => ['carrier:write']],
|
|
security: "is_granted('ROLE_ADMIN')"
|
|
),
|
|
new Patch(
|
|
requirements: ['id' => '\d+'],
|
|
normalizationContext: ['groups' => ['carrier:read']],
|
|
denormalizationContext: ['groups' => ['carrier:write']],
|
|
security: "is_granted('ROLE_ADMIN')"
|
|
),
|
|
],
|
|
security: "is_granted('ROLE_USER')",
|
|
)]
|
|
class Carrier
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read', 'shipment:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 180)]
|
|
#[Groups(['carrier:read', 'carrier:write', 'driver:read', 'vehicle:read', 'reception:read', 'shipment:read'])]
|
|
private string $name = '';
|
|
|
|
#[ORM\Column(length: 30, nullable: true)]
|
|
#[Groups(['carrier:read', 'carrier:write', 'driver:read', 'vehicle:read', 'reception:read', 'shipment:read'])]
|
|
private ?string $code = null;
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): self
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCode(): ?string
|
|
{
|
|
return $this->code;
|
|
}
|
|
|
|
public function setCode(?string $code): self
|
|
{
|
|
$this->code = $code;
|
|
|
|
return $this;
|
|
}
|
|
}
|