1010use PhpList \RestBundle \Controller \Traits \AuthenticationTrait ;
1111use PhpList \RestBundle \Entity \Request \CreateSubscriberListRequest ;
1212use PhpList \RestBundle \Serializer \SubscriberListNormalizer ;
13+ use PhpList \RestBundle \Service \Factory \PaginationCursorRequestFactory ;
1314use PhpList \RestBundle \Service \Manager \SubscriberListManager ;
15+ use PhpList \RestBundle \Service \Provider \SubscriberListProvider ;
1416use PhpList \RestBundle \Validator \RequestValidator ;
1517use Symfony \Bridge \Doctrine \Attribute \MapEntity ;
1618use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
@@ -35,17 +37,23 @@ class ListController extends AbstractController
3537 private SubscriberListNormalizer $ normalizer ;
3638 private SubscriberListManager $ subscriberListManager ;
3739 private RequestValidator $ validator ;
40+ private PaginationCursorRequestFactory $ paginationFactory ;
41+ private SubscriberListProvider $ subscriberListProvider ;
3842
3943 public function __construct (
4044 Authentication $ authentication ,
4145 SubscriberListNormalizer $ normalizer ,
4246 RequestValidator $ validator ,
43- SubscriberListManager $ subscriberListManager
47+ SubscriberListManager $ subscriberListManager ,
48+ PaginationCursorRequestFactory $ paginationFactory ,
49+ SubscriberListProvider $ subscriberListProvider
4450 ) {
4551 $ this ->authentication = $ authentication ;
4652 $ this ->normalizer = $ normalizer ;
4753 $ this ->validator = $ validator ;
4854 $ this ->subscriberListManager = $ subscriberListManager ;
55+ $ this ->paginationFactory = $ paginationFactory ;
56+ $ this ->subscriberListProvider = $ subscriberListProvider ;
4957 }
5058
5159 #[Route('' , name: 'get_lists ' , methods: ['GET ' ])]
@@ -63,36 +71,36 @@ public function __construct(
6371 schema: new OA \Schema (
6472 type: 'string '
6573 )
74+ ),
75+ new OA \Parameter (
76+ name: 'after_id ' ,
77+ description: 'Last id (starting from 0) ' ,
78+ in: 'query ' ,
79+ required: false ,
80+ schema: new OA \Schema (type: 'integer ' , default: 1 , minimum: 1 )
81+ ),
82+ new OA \Parameter (
83+ name: 'limit ' ,
84+ description: 'Number of results per page ' ,
85+ in: 'query ' ,
86+ required: false ,
87+ schema: new OA \Schema (type: 'integer ' , default: 25 , maximum: 100 , minimum: 1 )
6688 )
6789 ],
6890 responses: [
6991 new OA \Response (
7092 response: 200 ,
7193 description: 'Success ' ,
7294 content: new OA \JsonContent (
73- type: 'array ' ,
74- items: new OA \Items (
75- properties: [
76- new OA \Property (property: 'name ' , type: 'string ' , example: 'News ' ),
77- new OA \Property (
78- property: 'description ' ,
79- type: 'string ' ,
80- example: 'News (and some fun stuff) '
81- ),
82- new OA \Property (
83- property: 'creation_date ' ,
84- type: 'string ' ,
85- format: 'date-time ' ,
86- example: '2016-06-22T15:01:17+00:00 '
87- ),
88- new OA \Property (property: 'list_position ' , type: 'integer ' , example: 12 ),
89- new OA \Property (property: 'subject_prefix ' , type: 'string ' , example: 'phpList ' ),
90- new OA \Property (property: 'public ' , type: 'boolean ' , example: true ),
91- new OA \Property (property: 'category ' , type: 'string ' , example: 'news ' ),
92- new OA \Property (property: 'id ' , type: 'integer ' , example: 1 )
93- ],
94- type: 'object '
95- )
95+ properties: [
96+ new OA \Property (
97+ property: 'items ' ,
98+ type: 'array ' ,
99+ items: new OA \Items (ref: '#/components/schemas/SubscriberList ' )
100+ ),
101+ new OA \Property (property: 'pagination ' , ref: '#/components/schemas/CursorPagination ' )
102+ ],
103+ type: 'object '
96104 )
97105 ),
98106 new OA \Response (
@@ -105,13 +113,12 @@ public function __construct(
105113 public function getLists (Request $ request ): JsonResponse
106114 {
107115 $ this ->requireAuthentication ($ request );
108- $ data = $ this ->subscriberListManager ->getAll ();
109-
110- $ normalized = array_map (function ($ item ) {
111- return $ this ->normalizer ->normalize ($ item );
112- }, $ data );
116+ $ pagination = $ this ->paginationFactory ->fromRequest ($ request );
113117
114- return new JsonResponse ($ normalized , Response::HTTP_OK );
118+ return new JsonResponse (
119+ $ this ->subscriberListProvider ->getPaginatedList ($ pagination ),
120+ Response::HTTP_OK
121+ );
115122 }
116123
117124 #[Route('/{listId} ' , name: 'get_list ' , methods: ['GET ' ])]
@@ -140,19 +147,7 @@ public function getLists(Request $request): JsonResponse
140147 new OA \Response (
141148 response: 200 ,
142149 description: 'Success ' ,
143- content: new OA \JsonContent (
144- type: 'object ' ,
145- example: [
146- 'name ' => 'News ' ,
147- 'description ' => 'News (and some fun stuff) ' ,
148- 'creation_date ' => '2016-06-22T15:01:17+00:00 ' ,
149- 'list_position ' => 12 ,
150- 'subject_prefix ' => 'phpList ' ,
151- 'public ' => true ,
152- 'category ' => 'news ' ,
153- 'id ' => 1
154- ]
155- )
150+ content: new OA \JsonContent (ref: '#/components/schemas/SubscriberList ' )
156151 ),
157152 new OA \Response (
158153 response: 403 ,
@@ -276,19 +271,7 @@ public function deleteList(
276271 new OA \Response (
277272 response: 201 ,
278273 description: 'Success ' ,
279- content: new OA \JsonContent (
280- type: 'object ' ,
281- example: [
282- 'name ' => 'News ' ,
283- 'description ' => 'News (and some fun stuff) ' ,
284- 'creation_date ' => '2016-06-22T15:01:17+00:00 ' ,
285- 'list_position ' => 12 ,
286- 'subject_prefix ' => 'phpList ' ,
287- 'public ' => true ,
288- 'category ' => 'news ' ,
289- 'id ' => 1
290- ]
291- )
274+ content: new OA \JsonContent (ref: '#/components/schemas/SubscriberList ' )
292275 ),
293276 new OA \Response (
294277 response: 403 ,
0 commit comments