Skip to content

Commit b879fc6

Browse files
committed
Add: history to subscriber object
1 parent 953c350 commit b879fc6

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

src/Subscription/Controller/SubscriberController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function getSubscriber(Request $request, int $subscriberId): JsonResponse
339339
{
340340
$this->requireAuthentication($request);
341341

342-
$subscriber = $this->subscriberManager->getSubscriberById($subscriberId);
342+
$subscriber = $this->subscriberManager->getSubscriberDetails($subscriberId);
343343
$subscriberData = $this->subscriberNormalizer->normalize($subscriber);
344344

345345
return $this->json($subscriberData, Response::HTTP_OK);

src/Subscription/Serializer/SubscriberNormalizer.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use OpenApi\Attributes as OA;
88
use PhpList\Core\Domain\Subscription\Model\Subscriber;
9+
use PhpList\Core\Domain\Subscription\Model\SubscriberHistory;
910
use PhpList\Core\Domain\Subscription\Model\Subscription;
1011
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1112

@@ -20,24 +21,38 @@
2021
format: 'date-time',
2122
example: '2023-01-01T12:00:00Z',
2223
),
24+
new OA\Property(
25+
property: 'updated_at',
26+
type: 'string',
27+
format: 'date-time',
28+
example: '2026-01-01T12:00:00Z',
29+
),
2330
new OA\Property(property: 'confirmed', type: 'boolean', example: true),
2431
new OA\Property(property: 'blacklisted', type: 'boolean', example: false),
2532
new OA\Property(property: 'bounce_count', type: 'integer', example: 0),
2633
new OA\Property(property: 'unique_id', type: 'string', example: '69f4e92cf50eafca9627f35704f030f4'),
34+
new OA\Property(property: 'uuid', type: 'string', example: '69f4e92-cf50eaf-ca9627f-35704f-030f4'),
2735
new OA\Property(property: 'html_email', type: 'boolean', example: true),
2836
new OA\Property(property: 'disabled', type: 'boolean', example: false),
2937
new OA\Property(
3038
property: 'subscribed_lists',
3139
type: 'array',
3240
items: new OA\Items(ref: '#/components/schemas/SubscriberList')
3341
),
42+
new OA\Property(
43+
property: 'history',
44+
type: 'array',
45+
items: new OA\Items(ref: '#/components/schemas/SubscriberHistory')
46+
),
3447
],
3548
type: 'object'
3649
)]
3750
class SubscriberNormalizer implements NormalizerInterface
3851
{
39-
public function __construct(private readonly SubscriberListNormalizer $subscriberListNormalizer)
40-
{
52+
public function __construct(
53+
private readonly SubscriberListNormalizer $subscriberListNormalizer,
54+
private readonly SubscriberHistoryNormalizer $subscriberHistoryNormalizer,
55+
) {
4156
}
4257

4358
/**
@@ -53,15 +68,20 @@ public function normalize($object, string $format = null, array $context = []):
5368
'id' => $object->getId(),
5469
'email' => $object->getEmail(),
5570
'created_at' => $object->getCreatedAt()->format('Y-m-d\TH:i:sP'),
71+
'updated_at' => $object->getUpdatedAt()->format('Y-m-d\TH:i:sP'),
5672
'confirmed' => $object->isConfirmed(),
5773
'blacklisted' => $object->isBlacklisted(),
5874
'bounce_count' => $object->getBounceCount(),
5975
'unique_id' => $object->getUniqueId(),
76+
'uuid' => $object->getUuid(),
6077
'html_email' => $object->hasHtmlEmail(),
6178
'disabled' => $object->isDisabled(),
6279
'subscribed_lists' => array_map(function (Subscription $subscription) {
6380
return $this->subscriberListNormalizer->normalize($subscription->getSubscriberList());
6481
}, $object->getSubscriptions()->toArray()),
82+
'history' => array_map(function (SubscriberHistory $history) {
83+
return $this->subscriberHistoryNormalizer->normalize($history);
84+
}, $object->getHistory()),
6585
];
6686
}
6787

tests/Integration/Subscription/Controller/SubscriberListControllerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*
1919
* @author Oliver Klee <oliver@phplist.com>
2020
* @author Xheni Myrtaj <xheni@phplist.com>
21+
* @author Tatevik Grigoryan <tatevik@phplist.com>
2122
*/
2223
class SubscriberListControllerTest extends AbstractTestController
2324
{
@@ -260,10 +261,12 @@ public function testGetListMembersWithCurrentSessionKeyForExistingListWithSubscr
260261
'id' => 1,
261262
'email' => 'oliver@example.com',
262263
'created_at' => '2016-07-22T15:01:17+00:00',
264+
'updated_at' => '2016-08-23T19:50:43+00:00',
263265
'confirmed' => true,
264266
'blacklisted' => true,
265267
'bounce_count' => 17,
266268
'unique_id' => '95feb7fe7e06e6c11ca8d0c48cb46e89',
269+
'uuid' => '',
267270
'html_email' => true,
268271
'disabled' => true,
269272
'subscribed_lists' => [
@@ -278,14 +281,17 @@ public function testGetListMembersWithCurrentSessionKeyForExistingListWithSubscr
278281
'category' => '',
279282
],
280283
],
284+
'history' => [],
281285
], [
282286
'id' => 2,
283287
'email' => 'oliver1@example.com',
284288
'created_at' => '2016-07-22T15:01:17+00:00',
289+
'updated_at' => '2016-08-23T19:50:43+00:00',
285290
'confirmed' => true,
286291
'blacklisted' => true,
287292
'bounce_count' => 17,
288293
'unique_id' => '95feb7fe7e06e6c11ca8d0c48cb46e87',
294+
'uuid' => '',
289295
'html_email' => true,
290296
'disabled' => true,
291297
'subscribed_lists' => [
@@ -310,6 +316,7 @@ public function testGetListMembersWithCurrentSessionKeyForExistingListWithSubscr
310316
'category' => 'news',
311317
],
312318
],
319+
'history' => [],
313320
],
314321
],
315322
'pagination' => [

tests/Unit/Subscription/Serializer/SubscriberNormalizerTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpList\Core\Domain\Subscription\Model\Subscriber;
1010
use PhpList\Core\Domain\Subscription\Model\SubscriberList;
1111
use PhpList\Core\Domain\Subscription\Model\Subscription;
12+
use PhpList\RestBundle\Subscription\Serializer\SubscriberHistoryNormalizer;
1213
use PhpList\RestBundle\Subscription\Serializer\SubscriberListNormalizer;
1314
use PhpList\RestBundle\Subscription\Serializer\SubscriberNormalizer;
1415
use PHPUnit\Framework\TestCase;
@@ -18,7 +19,7 @@ class SubscriberNormalizerTest extends TestCase
1819
{
1920
public function testSupportsNormalization(): void
2021
{
21-
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer());
22+
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer(), new SubscriberHistoryNormalizer());
2223
$subscriber = $this->createMock(Subscriber::class);
2324

2425
$this->assertTrue($normalizer->supportsNormalization($subscriber));
@@ -46,20 +47,23 @@ public function testNormalize(): void
4647
$subscriber->method('isBlacklisted')->willReturn(false);
4748
$subscriber->method('getBounceCount')->willReturn(0);
4849
$subscriber->method('getUniqueId')->willReturn('abc123');
50+
$subscriber->method('getUuid')->willReturn('abc-123-abc-123');
4951
$subscriber->method('hasHtmlEmail')->willReturn(true);
5052
$subscriber->method('isDisabled')->willReturn(false);
5153
$subscriber->method('getSubscriptions')->willReturn(new ArrayCollection([$subscription]));
5254

53-
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer());
55+
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer(), new SubscriberHistoryNormalizer());
5456

5557
$expected = [
5658
'id' => 101,
5759
'email' => 'test@example.com',
5860
'created_at' => '2024-12-31T12:00:00+00:00',
61+
'updated_at' => '',
5962
'confirmed' => true,
6063
'blacklisted' => false,
6164
'bounce_count' => 0,
6265
'unique_id' => 'abc123',
66+
'uuid' => 'abc-123-abc-123',
6367
'html_email' => true,
6468
'disabled' => false,
6569
'subscribed_lists' => [
@@ -73,15 +77,16 @@ public function testNormalize(): void
7377
'public' => true,
7478
'category' => '',
7579
]
76-
]
80+
],
81+
'history' => [],
7782
];
7883

7984
$this->assertSame($expected, $normalizer->normalize($subscriber));
8085
}
8186

8287
public function testNormalizeWithInvalidObject(): void
8388
{
84-
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer());
89+
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer(), new SubscriberHistoryNormalizer());
8590
$this->assertSame([], $normalizer->normalize(new stdClass()));
8691
}
8792
}

0 commit comments

Comments
 (0)