<?php
namespace App\Containers\CrmSection\InsuranceCaseContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
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 Symfony\Component\Serializer\Annotation\MaxDepth;
use App\Ship\Entities\MediaEntity;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\CrmSection\InsuranceCaseContainer\Data\Repositories\InsuranceCaseFilesRepository;
use App\Containers\CrmSection\InsuranceCaseContainer\UI\ApiPlatform\Controllers\PostSetFileByBinaryController;
use App\Containers\CrmSection\InsuranceCaseContainer\UI\ApiPlatform\Controllers\DeleteFileController;
use App\Containers\CrmSection\InsuranceCaseContainer\Entities\InsuranceCaseEntity;
use App\Containers\CrmSection\InsuranceCaseContainer\Entities\InsuranceCaseFileSectionEntity;
// use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Файлы
*/
#[ApiResource(
routePrefix: '/crm',
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/insurance_case/files/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
// new Post(
// uriTemplate: '/insurance_case/files',
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
new Post(
uriTemplate: '/insurance_case/files/set_by_binary',
controller: PostSetFileByBinaryController::class,
deserialize: false,
validationContext: ['groups' => ['read', 'media_object_create']],
openapiContext: [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'insuranceCase' => [
'type' => 'string'
],
'section' => [
'type' => 'string'
],
'file' => [
'type' => 'string',
'format' => 'binary'
]
],
'required' => [
'insuranceCase',
'section',
'file'
]
]
]
]
]
],
security: "is_granted('ROLE_USER_CLIENT')"
),
// new Patch(
// uriTemplate: '/insurance_case/files/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
new Delete(
uriTemplate: '/insurance_case/files/{id}', requirements: ['id' => '\d+'],
controller: DeleteFileController::class,
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
),
new GetCollection(
uriTemplate: '/insurance_case/files',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'CRM_InsuranceCases'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'client' => 'exact',
'insuranceCase' => 'exact',
'section' => 'exact',
'client.name' => 'exact',
'client.lastName' => 'exact',
'client.patronymic' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(DateFilter::class, properties: ['createdAt', 'updatedAt'])]
#[ApiFilter(OrderFilter::class)]
// #[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['lastName'])]
#[ORM\Entity(repositoryClass: InsuranceCaseFilesRepository::class)]
#[ORM\Table(name: '`crm_insurance_case_files`')]
class InsuranceCaseFilesEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Клиент
#[ORM\ManyToOne(targetEntity: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false)]
#[MaxDepth(2)]
private ClientEntity $client;
// Страховой случай
#[ORM\ManyToOne(targetEntity: InsuranceCaseEntity::class)]
#[ORM\JoinColumn(name: 'insurance_case_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(2)]
private InsuranceCaseEntity $insuranceCase;
// Раздел
#[ORM\ManyToOne(targetEntity: InsuranceCaseFileSectionEntity::class)]
#[ORM\JoinColumn(name: 'section_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(1)]
private InsuranceCaseFileSectionEntity $section;
// Файл
#[ORM\ManyToOne(targetEntity: MediaEntity::class)]
#[ORM\JoinColumn(name: 'file_id', referencedColumnName: 'id', nullable: false)]
private MediaEntity $file;
#[ApiProperty(types: ['https://schema.org/contentUrl'])]
#[Groups(['read', 'media_object:read'])]
public ?string $contentUrl = null;
#[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()
{
return $this->id;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getInsuranceCase()
{
return $this->insuranceCase;
}
public function setInsuranceCase($insuranceCase)
{
$this->insuranceCase = $insuranceCase;
return $this;
}
public function getSection()
{
return $this->section;
}
public function setSection($section)
{
$this->section = $section;
return $this;
}
public function getFile()
{
return $this->file;
}
public function setFile($file)
{
$this->file = $file;
return $this;
}
}