src/Containers/ServiceSection/TrackingContainer/Entities/MileageEntity.php line 81

Open in your IDE?
  1. <?php
  2. namespace App\Containers\ServiceSection\TrackingContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Doctrine\DBAL\Types\Types;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. use Symfony\Component\Serializer\Annotation\Context;
  23. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  24. use App\Containers\ServiceSection\TrackingContainer\Data\Repositories\MileageRepository;
  25. use App\Containers\CrmSection\EquipmentContainer\Entities\ApplicationEntity;
  26. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  27. /** 
  28.  * Отслеживание пробега
  29. */
  30. #[ApiResource(
  31.     routePrefix'/service',
  32.     normalizationContext: [
  33.         'groups' => 'read',
  34.         'enable_max_depth' => true
  35.     ],
  36.     operations: [
  37.         new Get(
  38.             uriTemplate'/tracking_mileage/{id}'requirements: ['id' => '\d+'],
  39.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  40.         ),
  41.         new Patch(
  42.             uriTemplate'/tracking_mileage/{id}'requirements: ['id' => '\d+'],
  43.             security"is_granted('ROLE_ADMIN')"
  44.         ),
  45.         // new Put(
  46.         //     uriTemplate: '/tracking_mileage/{id}', requirements: ['id' => '\d+'],
  47.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  48.         // ),
  49.         new Delete(
  50.             uriTemplate'/tracking_mileage/{id}'requirements: ['id' => '\d+'],
  51.             security"is_granted('ROLE_ADMIN')"
  52.         ),
  53.         // new Post(
  54.         //     uriTemplate: '/tracking_mileage',
  55.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  56.         // ),
  57.         new GetCollection(
  58.             uriTemplate'/tracking_mileage',
  59.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  60.         ),
  61.     ],
  62.     shortName'Service_TrackingMileage'
  63. )]
  64. #[ApiFilter(SearchFilter::class, properties: [
  65.     'id' => 'exact',
  66.     'externalCode' => 'partial'
  67.     'application' => 'exact',
  68.     'application.carNumber' => 'partial'
  69. ])]
  70. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  71. #[ApiFilter(RangeFilter::class, properties: ['id''mileage'])]
  72. #[ApiFilter(BooleanFilter::class, properties: ['isSystemBlock'])]
  73. #[ApiFilter(DateFilter::class, properties: ['activationDate''deactivationDate'])]
  74. #[ApiFilter(OrderFilter::class)]
  75. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['externalCode'])]
  76. #[ORM\Entity(repositoryClassMileageRepository::class)]
  77. #[ORM\Table(name'`service_tracking_mileage`')]
  78. class MileageEntity
  79. {   
  80.     #[ORM\Id]
  81.     #[ORM\GeneratedValue]
  82.     #[ORM\Column(typeTypes::INTEGER)]
  83.     #[Groups(['read'])]
  84.     private ?int $id null;
  85.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  86.     #[Groups(['read'])]
  87.     private ?string $externalCode null;
  88.     // Заявка
  89.     #[ORM\ManyToOne(targetEntityApplicationEntity::class)]
  90.     #[ORM\JoinColumn(name'application_id'referencedColumnName'id'nullablefalse)]
  91.     #[Groups(['read'])]
  92.     #[MaxDepth(2)]
  93.     private ApplicationEntity $application;
  94.     // Дата активации
  95.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullablefalse)]
  96.     #[Context(
  97.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  98.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  99.     )]
  100.     #[Groups(['read'])]
  101.     private \DateTimeInterface $activationDate;
  102.     // Дата деактивации
  103.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  104.     #[Context(
  105.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  106.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  107.     )]
  108.     #[Groups(['read'])]
  109.     private ?\DateTimeInterface $deactivationDate null;
  110.     // Пробег (километры)
  111.     #[ORM\Column(typeTypes::FLOATscale3nullablefalse)]
  112.     #[Groups(['read'])]
  113.     private float $mileage;
  114.     // Системная блокировка
  115.     #[ORM\Column(typeTypes::BOOLEAN)]
  116.     #[Groups(['read'])]
  117.     private ?bool $isSystemBlock false;
  118.     #[Gedmo\Timestampable(on'create')]
  119.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  120.     #[Groups(['read'])]
  121.     protected $createdAt;
  122.     #[Gedmo\Timestampable(on'update')]
  123.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  124.     #[Groups(['read'])]
  125.     protected $updatedAt;
  126.     public function getId()
  127.     {
  128.         return $this->id;
  129.     }
  130.     public function getExternalCode()
  131.     {
  132.         return $this->externalCode;
  133.     }
  134.     public function setExternalCode($code)
  135.     {
  136.         $this->externalCode $code;
  137.         return $this;
  138.     }
  139.     public function getApplication()
  140.     {
  141.         return $this->application;
  142.     }
  143.     public function setApplication($application)
  144.     {
  145.         $this->application $application;
  146.         return $this;
  147.     }
  148.     public function setActivationDate(\DateTimeImmutable|null $date)
  149.     {
  150.         $this->activationDate $date;
  151.         return $this;
  152.     }
  153.     public function getActivationDate()
  154.     {
  155.         return $this->activationDate;
  156.     }
  157.     public function setDeactivationDate(\DateTimeImmutable|null $date)
  158.     {
  159.         $this->deactivationDate $date;
  160.         return $this;
  161.     }
  162.     public function getDeactivationDate()
  163.     {
  164.         return $this->deactivationDate;
  165.     }
  166.     public function getMileage()
  167.     {
  168.         return $this->mileage;
  169.     }
  170.     public function setMileage($value)
  171.     {
  172.         $this->mileage = ($value !== null round($value3) : null);
  173.         return $this;
  174.     }
  175.     public function getIsSystemBlock()
  176.     {
  177.         return $this->isSystemBlock;
  178.     }
  179.     public function setIsSystemBlock($value)
  180.     {
  181.         $this->isSystemBlock $value;
  182.         return $this;
  183.     }
  184.     public function getCreatedAt()
  185.     {
  186.         return $this->createdAt;
  187.     }
  188.     public function getUpdatedAt()
  189.     {
  190.         return $this->updatedAt;
  191.     }
  192. }