1010use PhpList \Core \Security \Authentication ;
1111use PhpList \RestBundle \Common \Controller \BaseController ;
1212use PhpList \RestBundle \Common \Validator \RequestValidator ;
13+ use PhpList \RestBundle \Subscription \Serializer \SubscribePageNormalizer ;
1314use Symfony \Component \HttpFoundation \JsonResponse ;
1415use Symfony \Component \HttpFoundation \Request ;
1516use Symfony \Component \HttpFoundation \Response ;
@@ -22,6 +23,7 @@ public function __construct(
2223 Authentication $ authentication ,
2324 RequestValidator $ validator ,
2425 private readonly SubscribePageManager $ subscribePageManager ,
26+ private readonly SubscribePageNormalizer $ normalizer ,
2527 ) {
2628 parent ::__construct ($ authentication , $ validator );
2729 }
@@ -82,12 +84,7 @@ public function getPage(Request $request, int $id): JsonResponse
8284
8385 $ page = $ this ->subscribePageManager ->getPage ($ id );
8486
85- return $ this ->json ([
86- 'id ' => $ page ->getId (),
87- 'title ' => $ page ->getTitle (),
88- 'active ' => $ page ->isActive (),
89- 'owner_id ' => $ page ->getOwner ()?->getId(),
90- ], Response::HTTP_OK );
87+ return $ this ->json ($ this ->normalizer ->normalize ($ page ), Response::HTTP_OK );
9188 }
9289
9390 #[Route('' , name: 'create ' , methods: ['POST ' ])]
@@ -160,11 +157,6 @@ public function createPage(Request $request): JsonResponse
160157
161158 $ page = $ this ->subscribePageManager ->createPage ($ title , $ active , $ admin );
162159
163- return $ this ->json ([
164- 'id ' => $ page ->getId (),
165- 'title ' => $ page ->getTitle (),
166- 'active ' => $ page ->isActive (),
167- 'owner_id ' => $ page ->getOwner ()?->getId(),
168- ], Response::HTTP_CREATED );
160+ return $ this ->json ($ this ->normalizer ->normalize ($ page ), Response::HTTP_CREATED );
169161 }
170162}
0 commit comments