src/Containers/SettingSection/ListContainer/Entities/ExchangeRateEntity.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Containers\SettingSection\ListContainer\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\OrderFilter;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\DBAL\Types\Types;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use App\Containers\SettingSection\ListContainer\Data\Repositories\ExchangeRateRepository;
  21. /** 
  22.  * Курс валют
  23. */
  24. #[ApiResource(
  25.     routePrefix'/list',
  26.     normalizationContext: ['groups' => 'read'],
  27.     operations: [
  28.         new Get(
  29.             uriTemplate'/exchange_rates/{id}'requirements: ['id' => '\d+'],
  30.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  31.         ),
  32.         new Patch(
  33.             uriTemplate'/exchange_rates/{id}'requirements: ['id' => '\d+'],
  34.             security"is_granted('ROLE_ADMIN')"
  35.         ),
  36.         // new Put(
  37.         //     uriTemplate: '/exchange_rates/{id}', requirements: ['id' => '\d+'],
  38.         //     security: "is_granted('ROLE_ADMIN')"
  39.         // ),
  40.         new Delete(
  41.             uriTemplate'/exchange_rates/{id}'requirements: ['id' => '\d+'],
  42.             security"is_granted('ROLE_ADMIN')"
  43.         ),
  44.         new Post(
  45.             uriTemplate'/exchange_rates',
  46.             security"is_granted('ROLE_ADMIN')"
  47.         ),
  48.         new GetCollection(
  49.             uriTemplate'/exchange_rates',
  50.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  51.         ),
  52.     ],
  53.     shortName'List_ExchangeRates'
  54. )]
  55. #[ApiFilter(SearchFilter::class, properties: ['id' => 'exact''currency' => 'exact'])]
  56. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  57. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  58. #[ApiFilter(DateFilter::class, properties: ['createdAt''updatedAt'])]
  59. #[ApiFilter(OrderFilter::class)]
  60. #[ORM\Entity(repositoryClassExchangeRateRepository::class)]
  61. #[ORM\Table(name'`list_exchange_rates`')]
  62. #[ORM\Index(columns: ['currency'], name'list_exchange_rates_custom_idx')]
  63. class ExchangeRateEntity
  64. {   
  65.     #[ORM\Id]
  66.     #[ORM\GeneratedValue]
  67.     #[ORM\Column(typeTypes::INTEGER)]
  68.     #[Groups(['read'])]
  69.     private ?int $id null;
  70.     // Валюта
  71.     #[ORM\Column(typeTypes::STRINGlength3nullablefalseuniquetrue)]
  72.     #[Groups(['read'])]
  73.     private string $currency;
  74.     // Значение
  75.     #[ORM\Column(typeTypes::FLOATscale3options: ['default' => 0])]
  76.     #[Groups(['read'])]
  77.     private float $value 0;
  78.     #[Gedmo\Timestampable(on'create')]
  79.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  80.     protected $createdAt;
  81.     #[Gedmo\Timestampable(on'update')]
  82.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  83.     protected $updatedAt;
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getCurrency()
  89.     {
  90.         return $this->currency;
  91.     }
  92.     public function setCurrency($currency)
  93.     {
  94.         $this->currency $currency;
  95.         return $this;
  96.     }
  97.     public function getValue()
  98.     {
  99.         return $this->value;
  100.     }
  101.     public function setValue($value)
  102.     {
  103.         $this->value = ($value !== null round($value3) : null);
  104.         return $this;
  105.     }
  106. }