Selaa lähdekoodia

filter contacts

master
Daniel 2 vuotta sitten
vanhempi
commit
9c4d1e7299
4 muutettua tiedostoa jossa 34 lisäystä ja 4 poistoa
  1. +26
    -0
      openapi.yaml
  2. +3
    -1
      src/ApiResource/ContactApi.php
  3. +1
    -1
      src/Mapper/ContactEntityToApiMapper.php
  4. +4
    -2
      src/Mapper/PartnerEntityToApiMapper.php

+ 26
- 0
openapi.yaml Näytä tiedosto

@@ -64,6 +64,32 @@ paths:
style: form
explode: 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
post:
operationId: api_contacts_post


+ 3
- 1
src/ApiResource/ContactApi.php Näytä tiedosto

@@ -7,7 +7,9 @@

namespace App\ApiResource;

use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Contact;
@@ -45,7 +47,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
processor: EntityClassDtoStateProcessor::class,
stateOptions: new Options(entityClass: Contact::class),
)]
#[ApiFilter(SearchFilter::class, properties: ['partner' => 'exact'])]
class ContactApi
{
#[ApiProperty(readable: false, writable: false, identifier: true)]


+ 1
- 1
src/Mapper/ContactEntityToApiMapper.php Näytä tiedosto

@@ -46,7 +46,7 @@ class ContactEntityToApiMapper implements MapperInterface
);
$dto->birthday = $entity->getBirthday();
$dto->image = $entity->getImage();
$dto->imageUrl = $entity->getImage()?->getFilePath();
$dto->imageUrl = $entity->getImage()?->getContentUrl();
$dto->position = $entity->getPosition();
$dto->phone = $entity->getPhone();
$dto->email = $entity->getEmail();


+ 4
- 2
src/Mapper/PartnerEntityToApiMapper.php Näytä tiedosto

@@ -9,12 +9,14 @@ use App\Entity\Partner;
use Symfonycasts\MicroMapper\AsMapper;
use Symfonycasts\MicroMapper\MapperInterface;
use Symfonycasts\MicroMapper\MicroMapperInterface;
use Vich\UploaderBundle\Storage\StorageInterface;

#[AsMapper(from: Partner::class, to: PartnerApi::class)]
class PartnerEntityToApiMapper implements MapperInterface
{
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->website = $entity->getWebsite();
$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->contacts = array_map(function(Contact $contact) {
return $this->microMapper->map($contact, ContactApi::class, [


Ladataan…
Peruuta
Tallenna