<?php
namespace App\Containers\CrmSection\EquipmentContainer\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\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 Symfony\Component\Serializer\Annotation\MaxDepth;
use App\Containers\CrmSection\EquipmentContainer\Data\Repositories\DamageRepository;
use App\Containers\CrmSection\EquipmentContainer\Entities\ApplicationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Повреждения
*/
#[ApiResource(
routePrefix: '/crm',
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/application_damages/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/application_damages/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
),
// new Put(
// uriTemplate: '/application_damages/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
new Delete(
uriTemplate: '/application_damages/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
),
new Post(
uriTemplate: '/application_damages',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
),
new GetCollection(
uriTemplate: '/application_damages',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
),
],
shortName: 'CRM_Equipments'
)]
#[ApiFilter(SearchFilter::class, properties: ['id' => 'exact', 'application' => 'exact', 'externalCode' => 'partial', 'placeDamage' => 'exact'])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class)]
#[ORM\Entity(repositoryClass: DamageRepository::class)]
#[ORM\Table(name: '`crm_equipments_damages`')]
class DamageEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $externalCode = null;
// Заявка
#[ORM\ManyToOne(targetEntity: ApplicationEntity::class)]
#[ORM\JoinColumn(name: 'application_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ApplicationEntity $application;
// Место повреждения
#[ORM\Column(type: Types::TEXT, nullable: false)]
#[Groups(['read'])]
private string $placeDamage;
// Описание повреждения
#[ORM\Column(type: Types::TEXT, nullable: false)]
#[Groups(['read'])]
private string $descriptionDamage;
// Комментарий
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read'])]
private ?string $comment = null;
// Сортировка
#[ORM\Column(type: Types::INTEGER, options: ['default' => 500])]
#[Groups(['read'])]
private int $sorting = 500;
#[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 setId($value)
{
$this->id = $value;
return $this;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getApplication()
{
return $this->application;
}
public function setApplication($application)
{
$this->application = $application;
return $this;
}
public function getPlaceDamage()
{
return $this->placeDamage;
}
public function setPlaceDamage($comment)
{
$this->placeDamage = $comment;
return $this;
}
public function getDescriptionDamage()
{
return $this->descriptionDamage;
}
public function setDescriptionDamage($description)
{
$this->descriptionDamage = $description;
return $this;
}
public function getComment()
{
return $this->comment;
}
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
public function getSorting()
{
return $this->sorting;
}
public function setSorting($value)
{
$this->sorting = $value;
return $this;
}
public function setCreatedAt(\DateTimeImmutable|null $date)
{
$this->createdAt = $date;
return $this;
}
public function setUpdatedAt(\DateTimeImmutable|null $date)
{
$this->updatedAt = $date;
return $this;
}
}