44
55namespace PhpList \RestBundle \Controller ;
66
7- use PhpList \RestBundle \Serializer \SubscriberNormalizer ;
8- use Symfony \Bridge \Doctrine \Attribute \MapEntity ;
97use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
108use PhpList \Core \Domain \Model \Subscription \Subscriber ;
119use PhpList \Core \Domain \Repository \Subscription \SubscriberRepository ;
@@ -30,16 +28,11 @@ class SubscriberController extends AbstractController
3028 use AuthenticationTrait;
3129
3230 private SubscriberRepository $ subscriberRepository ;
33- private SubscriberNormalizer $ subscriberNormalizer ;
3431
35- public function __construct (
36- Authentication $ authentication ,
37- SubscriberRepository $ repository ,
38- SubscriberNormalizer $ subscriberNormalizer
39- ) {
32+ public function __construct (Authentication $ authentication , SubscriberRepository $ repository )
33+ {
4034 $ this ->authentication = $ authentication ;
4135 $ this ->subscriberRepository = $ repository ;
42- $ this ->subscriberNormalizer = $ subscriberNormalizer ;
4336 }
4437
4538 #[Route('/subscribers ' , name: 'create_subscriber ' , methods: ['POST ' ])]
@@ -189,25 +182,41 @@ public function postAction(Request $request, SerializerInterface $serializer): J
189182 description: 'Success ' ,
190183 content: new OA \JsonContent (
191184 properties: [
185+ new OA \Property (property: 'id ' , type: 'integer ' , example: 1 ),
186+ new OA \
Property (property:
'email ' , type:
'string ' , example:
'[email protected] ' ),
192187 new OA \Property (
193188 property: 'creation_date ' ,
194189 type: 'string ' ,
195190 format: 'date-time ' ,
196- example: '2017-12-16T18:44:27+ 00:00 '
191+ example: '2023-01-01T12: 00:00Z '
197192 ),
198- new OA \
Property (property:
'email ' , type:
'string ' , example:
'[email protected] ' ),
199- new OA \Property (property: 'confirmed ' , type: 'boolean ' , example: false ),
193+ new OA \Property (property: 'confirmed ' , type: 'boolean ' , example: true ),
200194 new OA \Property (property: 'blacklisted ' , type: 'boolean ' , example: false ),
201- new OA \Property (property: 'bounced ' , type: 'integer ' , example: 0 ),
195+ new OA \Property (property: 'bounce_count ' , type: 'integer ' , example: 0 ),
196+ new OA \Property (property: 'unique_id ' , type: 'string ' , example: 'abc123 ' ),
197+ new OA \Property (property: 'html_email ' , type: 'boolean ' , example: true ),
198+ new OA \Property (property: 'disabled ' , type: 'boolean ' , example: false ),
202199 new OA \Property (
203- property: 'unique_id ' ,
204- type: 'string ' ,
205- example: '69f4e92cf50eafca9627f35704f030f4 '
200+ property: 'subscribedLists ' ,
201+ type: 'array ' ,
202+ items: new OA \Items (
203+ properties: [
204+ new OA \Property (property: 'id ' , type: 'integer ' , example: 2 ),
205+ new OA \Property (property: 'name ' , type: 'string ' , example: 'Newsletter ' ),
206+ new OA \Property (property: 'description ' , type: 'string ' , example: 'Monthly updates ' ),
207+ new OA \Property (
208+ property: 'creation_date ' ,
209+ type: 'string ' ,
210+ format: 'date-time ' ,
211+ example: '2022-12-01T10:00:00Z '
212+ ),
213+ new OA \Property (property: 'public ' , type: 'boolean ' , example: true ),
214+ ],
215+ type: 'object '
216+ )
206217 ),
207- new OA \Property (property: 'html_email ' , type: 'boolean ' , example: false ),
208- new OA \Property (property: 'disabled ' , type: 'boolean ' , example: false ),
209- new OA \Property (property: 'id ' , type: 'integer ' , example: 1 )
210- ]
218+ ],
219+ type: 'object '
211220 )
212221 ),
213222 new OA \Response (
@@ -229,21 +238,19 @@ public function postAction(Request $request, SerializerInterface $serializer): J
229238 )
230239 ]
231240 )]
232- public function getAction (
233- Request $ request ,
234- #[MapEntity(mapping: ['subscriberId ' => 'id ' ])] Subscriber $ subscriber ,
235- ): JsonResponse {
241+ public function getAction (Request $ request , int $ subscriberId , SerializerInterface $ serializer ): JsonResponse
242+ {
236243 $ this ->requireAuthentication ($ request );
237244
238- $ subscriber = $ this ->subscriberRepository ->findSubscriberWithSubscriptions ($ subscriber -> getId () );
245+ $ subscriber = $ this ->subscriberRepository ->findSubscriberWithSubscriptions ($ subscriberId );
239246
240247 if (!$ subscriber ) {
241248 return new JsonResponse (['error ' => 'Subscriber not found ' ], Response::HTTP_NOT_FOUND );
242249 }
243250
244- $ data = $ this -> subscriberNormalizer -> normalize ($ subscriber );
251+ $ data = $ serializer -> serialize ($ subscriber, ' json ' );
245252
246- return new JsonResponse ($ data , Response::HTTP_OK , []);
253+ return new JsonResponse ($ data , Response::HTTP_OK , [], true );
247254 }
248255
249256 /**
0 commit comments