10
10
use PhpList \Core \Security \Authentication ;
11
11
use PhpList \RestBundle \Common \Controller \BaseController ;
12
12
use PhpList \RestBundle \Common \Validator \RequestValidator ;
13
+ use PhpList \RestBundle \Subscription \Serializer \SubscribePageNormalizer ;
13
14
use Symfony \Component \HttpFoundation \JsonResponse ;
14
15
use Symfony \Component \HttpFoundation \Request ;
15
16
use Symfony \Component \HttpFoundation \Response ;
@@ -22,6 +23,7 @@ public function __construct(
22
23
Authentication $ authentication ,
23
24
RequestValidator $ validator ,
24
25
private readonly SubscribePageManager $ subscribePageManager ,
26
+ private readonly SubscribePageNormalizer $ normalizer ,
25
27
) {
26
28
parent ::__construct ($ authentication , $ validator );
27
29
}
@@ -82,12 +84,7 @@ public function getPage(Request $request, int $id): JsonResponse
82
84
83
85
$ page = $ this ->subscribePageManager ->getPage ($ id );
84
86
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 );
91
88
}
92
89
93
90
#[Route('' , name: 'create ' , methods: ['POST ' ])]
@@ -160,11 +157,6 @@ public function createPage(Request $request): JsonResponse
160
157
161
158
$ page = $ this ->subscribePageManager ->createPage ($ title , $ active , $ admin );
162
159
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 );
169
161
}
170
162
}
0 commit comments