| @@ -64,6 +64,32 @@ paths: | |||||
| style: form | style: form | ||||
| explode: false | explode: false | ||||
| allowReserved: false | allowReserved: false | ||||
| - | |||||
| name: partner | |||||
| in: query | |||||
| description: '' | |||||
| required: false | |||||
| deprecated: false | |||||
| allowEmptyValue: true | |||||
| schema: | |||||
| type: string | |||||
| style: form | |||||
| explode: false | |||||
| allowReserved: false | |||||
| - | |||||
| name: 'partner[]' | |||||
| in: query | |||||
| description: '' | |||||
| required: false | |||||
| deprecated: false | |||||
| allowEmptyValue: true | |||||
| schema: | |||||
| type: array | |||||
| items: | |||||
| type: string | |||||
| style: form | |||||
| explode: true | |||||
| allowReserved: false | |||||
| deprecated: false | deprecated: false | ||||
| post: | post: | ||||
| operationId: api_contacts_post | operationId: api_contacts_post | ||||
| @@ -7,7 +7,9 @@ | |||||
| namespace App\ApiResource; | namespace App\ApiResource; | ||||
| use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; | |||||
| use ApiPlatform\Doctrine\Orm\State\Options; | use ApiPlatform\Doctrine\Orm\State\Options; | ||||
| use ApiPlatform\Metadata\ApiFilter; | |||||
| use ApiPlatform\Metadata\ApiProperty; | use ApiPlatform\Metadata\ApiProperty; | ||||
| use ApiPlatform\Metadata\ApiResource; | use ApiPlatform\Metadata\ApiResource; | ||||
| use App\Entity\Contact; | use App\Entity\Contact; | ||||
| @@ -45,7 +47,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||||
| processor: EntityClassDtoStateProcessor::class, | processor: EntityClassDtoStateProcessor::class, | ||||
| stateOptions: new Options(entityClass: Contact::class), | stateOptions: new Options(entityClass: Contact::class), | ||||
| )] | )] | ||||
| #[ApiFilter(SearchFilter::class, properties: ['partner' => 'exact'])] | |||||
| class ContactApi | class ContactApi | ||||
| { | { | ||||
| #[ApiProperty(readable: false, writable: false, identifier: true)] | #[ApiProperty(readable: false, writable: false, identifier: true)] | ||||
| @@ -46,7 +46,7 @@ class ContactEntityToApiMapper implements MapperInterface | |||||
| ); | ); | ||||
| $dto->birthday = $entity->getBirthday(); | $dto->birthday = $entity->getBirthday(); | ||||
| $dto->image = $entity->getImage(); | $dto->image = $entity->getImage(); | ||||
| $dto->imageUrl = $entity->getImage()?->getFilePath(); | |||||
| $dto->imageUrl = $entity->getImage()?->getContentUrl(); | |||||
| $dto->position = $entity->getPosition(); | $dto->position = $entity->getPosition(); | ||||
| $dto->phone = $entity->getPhone(); | $dto->phone = $entity->getPhone(); | ||||
| $dto->email = $entity->getEmail(); | $dto->email = $entity->getEmail(); | ||||
| @@ -9,12 +9,14 @@ use App\Entity\Partner; | |||||
| use Symfonycasts\MicroMapper\AsMapper; | use Symfonycasts\MicroMapper\AsMapper; | ||||
| use Symfonycasts\MicroMapper\MapperInterface; | use Symfonycasts\MicroMapper\MapperInterface; | ||||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | use Symfonycasts\MicroMapper\MicroMapperInterface; | ||||
| use Vich\UploaderBundle\Storage\StorageInterface; | |||||
| #[AsMapper(from: Partner::class, to: PartnerApi::class)] | #[AsMapper(from: Partner::class, to: PartnerApi::class)] | ||||
| class PartnerEntityToApiMapper implements MapperInterface | class PartnerEntityToApiMapper implements MapperInterface | ||||
| { | { | ||||
| public function __construct( | public function __construct( | ||||
| private MicroMapperInterface $microMapper | |||||
| private MicroMapperInterface $microMapper, | |||||
| private StorageInterface $storage | |||||
| ) { | ) { | ||||
| } | } | ||||
| @@ -45,7 +47,7 @@ class PartnerEntityToApiMapper implements MapperInterface | |||||
| $dto->country = $entity->getCountry(); | $dto->country = $entity->getCountry(); | ||||
| $dto->website = $entity->getWebsite(); | $dto->website = $entity->getWebsite(); | ||||
| $dto->logo = $entity->getLogo(); | $dto->logo = $entity->getLogo(); | ||||
| $dto->logoUrl = $entity->getLogo()?->getFilePath(); | |||||
| $dto->logoUrl = $entity->getLogo() !== null ? $this->storage->resolveUri($entity->getLogo(), 'file') : null; | |||||
| $dto->createdAt = $entity->getCreatedAt(); | $dto->createdAt = $entity->getCreatedAt(); | ||||
| $dto->contacts = array_map(function(Contact $contact) { | $dto->contacts = array_map(function(Contact $contact) { | ||||
| return $this->microMapper->map($contact, ContactApi::class, [ | return $this->microMapper->map($contact, ContactApi::class, [ | ||||