|
12 | 12 | use PhpList\Core\Security\Authentication; |
13 | 13 | use PhpList\RestBundle\Common\Controller\BaseController; |
14 | 14 | use PhpList\RestBundle\Common\Validator\RequestValidator; |
| 15 | +use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider; |
15 | 16 | use PhpList\RestBundle\Subscription\Request\CreateSubscriberRequest; |
16 | 17 | use PhpList\RestBundle\Subscription\Request\UpdateSubscriberRequest; |
17 | 18 | use PhpList\RestBundle\Subscription\Serializer\SubscriberNormalizer; |
@@ -39,11 +40,79 @@ public function __construct( |
39 | 40 | private readonly SubscriberNormalizer $subscriberNormalizer, |
40 | 41 | private readonly SubscriberHistoryService $subscriberHistoryService, |
41 | 42 | private readonly EntityManagerInterface $entityManager, |
| 43 | + private readonly PaginatedDataProvider $paginatedDataProvider, |
42 | 44 | ) { |
43 | 45 | parent::__construct($authentication, $validator); |
44 | 46 | $this->authentication = $authentication; |
45 | 47 | } |
46 | 48 |
|
| 49 | + #[Route('', name: 'get_list', methods: ['GET'])] |
| 50 | + #[OA\Get( |
| 51 | + path: '/api/v2/subscribers', |
| 52 | + description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . |
| 53 | + 'Returns a JSON list of all subscribers.', |
| 54 | + summary: 'Gets a list of all subscribers.', |
| 55 | + tags: ['subscribers'], |
| 56 | + parameters: [ |
| 57 | + new OA\Parameter( |
| 58 | + name: 'php-auth-pw', |
| 59 | + description: 'Session key obtained from login', |
| 60 | + in: 'header', |
| 61 | + required: true, |
| 62 | + schema: new OA\Schema(type: 'string') |
| 63 | + ), |
| 64 | + new OA\Parameter( |
| 65 | + name: 'after_id', |
| 66 | + description: 'Last id (starting from 0)', |
| 67 | + in: 'query', |
| 68 | + required: false, |
| 69 | + schema: new OA\Schema(type: 'integer', default: 1, minimum: 1) |
| 70 | + ), |
| 71 | + new OA\Parameter( |
| 72 | + name: 'limit', |
| 73 | + description: 'Number of results per page', |
| 74 | + in: 'query', |
| 75 | + required: false, |
| 76 | + schema: new OA\Schema(type: 'integer', default: 25, maximum: 100, minimum: 1) |
| 77 | + ) |
| 78 | + ], |
| 79 | + responses: [ |
| 80 | + new OA\Response( |
| 81 | + response: 200, |
| 82 | + description: 'Success', |
| 83 | + content: new OA\JsonContent( |
| 84 | + properties: [ |
| 85 | + new OA\Property( |
| 86 | + property: 'items', |
| 87 | + type: 'array', |
| 88 | + items: new OA\Items(ref: '#/components/schemas/Subscriber') |
| 89 | + ), |
| 90 | + new OA\Property(property: 'pagination', ref: '#/components/schemas/CursorPagination') |
| 91 | + ], |
| 92 | + type: 'object' |
| 93 | + ) |
| 94 | + ), |
| 95 | + new OA\Response( |
| 96 | + response: 403, |
| 97 | + description: 'Failure', |
| 98 | + content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') |
| 99 | + ) |
| 100 | + ] |
| 101 | + )] |
| 102 | + public function getSubscribers(Request $request): JsonResponse |
| 103 | + { |
| 104 | + $this->requireAuthentication($request); |
| 105 | + |
| 106 | + return $this->json( |
| 107 | + $this->paginatedDataProvider->getPaginatedList( |
| 108 | + $request, |
| 109 | + $this->subscriberNormalizer, |
| 110 | + Subscriber::class |
| 111 | + ), |
| 112 | + Response::HTTP_OK |
| 113 | + ); |
| 114 | + } |
| 115 | + |
47 | 116 | #[Route('', name: 'create', methods: ['POST'])] |
48 | 117 | #[OA\Post( |
49 | 118 | path: '/api/v2/subscribers', |
|
0 commit comments