Преглед изворни кода

partner products mapping

master
Daniel пре 1 година
родитељ
комит
78b16df76f
2 измењених фајлова са 16 додато и 0 уклоњено
  1. +6
    -0
      src/ApiResource/PartnerApi.php
  2. +10
    -0
      src/Mapper/PartnerEntityToApiMapper.php

+ 6
- 0
src/ApiResource/PartnerApi.php Прегледај датотеку

@@ -101,4 +101,10 @@ class PartnerApi
*/ */
#[ApiProperty(writable: false)] #[ApiProperty(writable: false)]
public array $contacts = []; public array $contacts = [];

/**
* @var array<int, ContactApi>
*/
#[ApiProperty(writable: false)]
public array $partnerProducts = [];
} }

+ 10
- 0
src/Mapper/PartnerEntityToApiMapper.php Прегледај датотеку

@@ -4,10 +4,12 @@ namespace App\Mapper;


use App\ApiResource\ContactApi; use App\ApiResource\ContactApi;
use App\ApiResource\PartnerApi; use App\ApiResource\PartnerApi;
use App\ApiResource\PartnerProductApi;
use App\ApiResource\PostingApi; use App\ApiResource\PostingApi;
use App\ApiResource\UserApi; use App\ApiResource\UserApi;
use App\Entity\Contact; use App\Entity\Contact;
use App\Entity\Partner; use App\Entity\Partner;
use App\Entity\PartnerProduct;
use App\Entity\Posting; use App\Entity\Posting;
use App\Service\FileUrlService; use App\Service\FileUrlService;
use Symfonycasts\MicroMapper\AsMapper; use Symfonycasts\MicroMapper\AsMapper;
@@ -63,11 +65,19 @@ class PartnerEntityToApiMapper implements MapperInterface
MicroMapperInterface::MAX_DEPTH => 1, MicroMapperInterface::MAX_DEPTH => 1,
]); ]);
}, $entity->getPostings()->getValues()); }, $entity->getPostings()->getValues());

$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, [
MicroMapperInterface::MAX_DEPTH => 1, MicroMapperInterface::MAX_DEPTH => 1,
]); ]);
}, $entity->getContacts()->getValues()); }, $entity->getContacts()->getValues());

$dto->partnerProducts = array_map(function(PartnerProduct $contact) {
return $this->microMapper->map($contact, PartnerProductApi::class, [
MicroMapperInterface::MAX_DEPTH => 1,
]);
}, $entity->getPartnerProducts()->getValues());

return $dto; return $dto;
} }
} }

Loading…
Откажи
Сачувај