Skip to content

Commit 11181e6

Browse files
committed
getByPage data
1 parent e70d140 commit 11181e6

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

src/Domain/Subscription/Repository/SubscriberPageDataRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ public function findByPageAndName(SubscribePage $page, string $name): ?Subscribe
1818
{
1919
return $this->findOneBy(['id' => $page->getId(), 'name' => $name]);
2020
}
21+
22+
/** @return SubscribePageData[] */
23+
public function getByPage(SubscribePage $page): array
24+
{
25+
return $this->findBy(['id' => $page->getId()]);
26+
}
2127
}

src/Domain/Subscription/Repository/SubscriberPageRepository.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@
77
use PhpList\Core\Domain\Common\Repository\AbstractRepository;
88
use PhpList\Core\Domain\Common\Repository\CursorPaginationTrait;
99
use PhpList\Core\Domain\Common\Repository\Interfaces\PaginatableRepositoryInterface;
10+
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
11+
use PhpList\Core\Domain\Subscription\Model\SubscribePageData;
1012

1113
class SubscriberPageRepository extends AbstractRepository implements PaginatableRepositoryInterface
1214
{
1315
use CursorPaginationTrait;
16+
17+
/** @return array{page: SubscribePage, data: SubscribePageData}[] */
18+
public function findPagesWithData(int $pageId): array
19+
{
20+
return $this->createQueryBuilder('p')
21+
->select('p AS page, d AS data')
22+
->from(SubscribePage::class, 'p')
23+
->from(SubscribePageData::class, 'd')
24+
->where('p.id = :id')
25+
->andWhere('d.id = p.id')
26+
->setParameter('id', $pageId)
27+
->getQuery()
28+
->getResult();
29+
}
1430
}

src/Domain/Subscription/Service/Manager/SubscribePageManager.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ public function deletePage(SubscribePage $page): void
7979
$this->pageRepository->remove($page);
8080
}
8181

82-
public function getPageData(SubscribePage $page, string $name): ?string
82+
/** @return SubscribePageData[] */
83+
public function getPageData(SubscribePage $page): array
8384
{
84-
/** @var SubscribePageData|null $data */
85-
$data = $this->pageDataRepository->findByPageAndName($page, $name);
86-
return $data?->getData();
85+
return $this->pageDataRepository->getByPage($page,);
8786
}
8887

8988
public function setPageData(SubscribePage $page, string $name, ?string $value): SubscribePageData

tests/Unit/Domain/Subscription/Service/Manager/SubscribePageManagerTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ public function testGetPageDataReturnsStringWhenFound(): void
153153

154154
$this->pageDataRepository
155155
->expects($this->once())
156-
->method('findByPageAndName')
157-
->with($page, 'key')
158-
->willReturn($data);
156+
->method('getByPage')
157+
->with($page)
158+
->willReturn([$data]);
159159

160-
$result = $this->manager->getPageData($page, 'key');
161-
$this->assertSame('value', $result);
160+
$result = $this->manager->getPageData($page);
161+
$this->assertIsArray($result);
162+
$this->assertSame('value', $result[0]->getData());
162163
}
163164

164165
public function testGetPageDataReturnsNullWhenNotFound(): void
@@ -167,12 +168,12 @@ public function testGetPageDataReturnsNullWhenNotFound(): void
167168

168169
$this->pageDataRepository
169170
->expects($this->once())
170-
->method('findByPageAndName')
171-
->with($page, 'missing')
172-
->willReturn(null);
171+
->method('getByPage')
172+
->with($page)
173+
->willReturn([]);
173174

174-
$result = $this->manager->getPageData($page, 'missing');
175-
$this->assertNull($result);
175+
$result = $this->manager->getPageData($page);
176+
$this->assertEmpty($result);
176177
}
177178

178179
public function testSetPageDataUpdatesExistingDataAndFlushes(): void

0 commit comments

Comments
 (0)