|
4 | 4 |
|
5 | 5 | namespace App\Controller\Attendee; |
6 | 6 |
|
7 | | -use App\Repository\AttendeeRepository; |
| 7 | +use App\Pagination\AttendeeCollectionFactory; |
| 8 | +use Symfony\Component\HttpFoundation\Request; |
8 | 9 | use Symfony\Component\HttpFoundation\Response; |
9 | 10 | use Symfony\Component\Routing\Annotation\Route; |
10 | 11 | use Symfony\Component\Serializer\SerializerInterface; |
|
13 | 14 | final class ListController |
14 | 15 | { |
15 | 16 | public function __construct( |
16 | | - private AttendeeRepository $attendeeRepository, |
| 17 | + private AttendeeCollectionFactory $attendeeCollectionFactory, |
17 | 18 | private SerializerInterface $serializer, |
18 | 19 | ) { |
19 | 20 | } |
20 | 21 |
|
21 | | - public function __invoke(): Response |
| 22 | + public function __invoke(Request $request): Response |
22 | 23 | { |
23 | | - $allAttendees = $this->attendeeRepository->findAll(); |
| 24 | + $attendeeCollection = $this->attendeeCollectionFactory->create( |
| 25 | + $request->query->getInt('page', 1), |
| 26 | + $request->query->getInt('size', 10) |
| 27 | + ); |
24 | 28 |
|
25 | | - $serializedAttendees = $this->serializer->serialize($allAttendees, 'json'); |
| 29 | + $serializedAttendeeCollection = $this->serializer->serialize($attendeeCollection, 'json'); |
26 | 30 |
|
27 | | - return new Response($serializedAttendees, Response::HTTP_OK, [ |
| 31 | + return new Response($serializedAttendeeCollection, Response::HTTP_OK, [ |
28 | 32 | 'Content-Type' => 'application/json', |
29 | 33 | ]); |
30 | 34 | } |
|
0 commit comments