<?php
namespace App\Containers\SettingSection\ListContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Containers\SettingSection\ListContainer\Data\Repositories\ExchangeRateRepository;
/**
* Курс валют
*/
#[ApiResource(
routePrefix: '/list',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/exchange_rates/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/exchange_rates/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/exchange_rates/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
new Delete(
uriTemplate: '/exchange_rates/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/exchange_rates',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/exchange_rates',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'List_ExchangeRates'
)]
#[ApiFilter(SearchFilter::class, properties: ['id' => 'exact', 'currency' => 'exact'])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(DateFilter::class, properties: ['createdAt', 'updatedAt'])]
#[ApiFilter(OrderFilter::class)]
#[ORM\Entity(repositoryClass: ExchangeRateRepository::class)]
#[ORM\Table(name: '`list_exchange_rates`')]
#[ORM\Index(columns: ['currency'], name: 'list_exchange_rates_custom_idx')]
class ExchangeRateEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Валюта
#[ORM\Column(type: Types::STRING, length: 3, nullable: false, unique: true)]
#[Groups(['read'])]
private string $currency;
// Значение
#[ORM\Column(type: Types::FLOAT, scale: 3, options: ['default' => 0])]
#[Groups(['read'])]
private float $value = 0;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $updatedAt;
public function getId(): ?int
{
return $this->id;
}
public function getCurrency()
{
return $this->currency;
}
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = ($value !== null ? round($value, 3) : null);
return $this;
}
}