Skip to content

Commit 2748491

Browse files
committed
Add: Reset subscriber bounce count
1 parent ffa7078 commit 2748491

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/Subscription/Controller/SubscriberController.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,74 @@ public function deleteSubscriber(
375375
return $this->json(null, Response::HTTP_NO_CONTENT);
376376
}
377377

378+
#[Route(
379+
'/{subscriberId}/reset-bounce-count',
380+
name: 'reset_bounce_count',
381+
requirements: ['subscriberId' => '\d+'],
382+
methods: ['POST']
383+
)]
384+
#[OA\Post(
385+
path: '/api/v2/subscribers/{subscriberId}/reset-bounce-count',
386+
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production.',
387+
summary: 'Reset bounce count for a subscriber.',
388+
tags: ['subscribers'],
389+
parameters: [
390+
new OA\Parameter(
391+
name: 'php-auth-pw',
392+
description: 'Session key obtained from login',
393+
in: 'header',
394+
required: true,
395+
schema: new OA\Schema(type: 'string')
396+
),
397+
new OA\Parameter(
398+
name: 'subscriberId',
399+
description: 'Subscriber ID',
400+
in: 'path',
401+
required: true,
402+
schema: new OA\Schema(type: 'string')
403+
)
404+
],
405+
responses: [
406+
new OA\Response(
407+
response: 200,
408+
description: 'Success',
409+
content: new OA\JsonContent(ref: '#/components/schemas/Subscriber'),
410+
),
411+
new OA\Response(
412+
response: 403,
413+
description: 'Failure',
414+
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
415+
),
416+
new OA\Response(
417+
response: 422,
418+
description: 'Failure',
419+
content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse')
420+
),
421+
new OA\Response(
422+
response: 404,
423+
description: 'Failure',
424+
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
425+
)
426+
]
427+
)]
428+
public function resetBounceCount(
429+
Request $request,
430+
#[MapEntity(mapping: ['subscriberId' => 'id'])] ?Subscriber $subscriber = null,
431+
): Response {
432+
$admin = $this->requireAuthentication($request);
433+
if (!$admin->getPrivileges()->has(PrivilegeFlag::Subscribers)) {
434+
throw $this->createAccessDeniedException('You are not allowed to manage Subscribers.');
435+
}
436+
437+
if (!$subscriber) {
438+
throw $this->createNotFoundException('Subscriber not found.');
439+
}
440+
441+
$subscriberData = $this->subscriberService->resetSubscriberBounceCount($subscriber);
442+
443+
return $this->json($subscriberData, Response::HTTP_OK);
444+
}
445+
378446
#[Route('/confirm', name: 'confirm', methods: ['GET'])]
379447
#[OA\Get(
380448
path: '/api/v2/subscribers/confirm',

src/Subscription/Service/SubscriberService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
use Symfony\Component\HttpFoundation\Request;
1313
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1414

15+
/**
16+
* This encapsulates subscriber-related services
17+
*
18+
* @author Tatevik Grigoryan <[email protected]>
19+
*/
1520
class SubscriberService
1621
{
1722
public function __construct(
@@ -33,6 +38,12 @@ public function updateSubscriber(UpdateSubscriberRequest $updateSubscriberReques
3338
return $this->subscriberNormalizer->normalize($subscriber, 'json');
3439
}
3540

41+
public function resetSubscriberBounceCount(Subscriber $subscriber): array
42+
{
43+
$subscriber = $this->subscriberManager->resetBounceCount($subscriber);
44+
return $this->subscriberNormalizer->normalize($subscriber, 'json');
45+
}
46+
3647
public function getSubscriber(int $subscriberId): array
3748
{
3849
$subscriber = $this->subscriberManager->getSubscriberById($subscriberId);

0 commit comments

Comments
 (0)