瀏覽代碼

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

$dto->contacts = array_map(function(Contact $contact) {
return $this->microMapper->map($contact, ContactApi::class, [
MicroMapperInterface::MAX_DEPTH => 1,
]);
}, $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;
}
}

Loading…
取消
儲存