diff --git a/src/Controller/StarshipApiController.php b/src/Controller/StarshipApiController.php index 469e6d0..c5cc075 100644 --- a/src/Controller/StarshipApiController.php +++ b/src/Controller/StarshipApiController.php @@ -2,8 +2,7 @@ namespace App\Controller; -use App\Model\Starship; -use Psr\Log\LoggerInterface; +use App\Repository\StarshipRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -11,17 +10,9 @@ use Symfony\Component\Routing\Attribute\Route; class StarshipApiController extends AbstractController { #[Route('/api/starships', name: 'starships')] - public function getCollection(LoggerInterface $logger): Response + public function getCollection(StarshipRepository $starshipRepository): Response { - $logger->info('Starships get collection'); - $starships = [ - new Starship( - 1, 'Starship 01', 'Heavy Starship', 'Human Captain', 'damaged', - ), - new Starship( - 2, 'Starship 02', 'Light Starship', 'Robot Captain', 'new', - ), - ]; + $starships = $starshipRepository->findAll(); return $this->json($starships); } diff --git a/src/Repository/StarshipRepository.php b/src/Repository/StarshipRepository.php new file mode 100644 index 0000000..5f3b436 --- /dev/null +++ b/src/Repository/StarshipRepository.php @@ -0,0 +1,27 @@ +logger->info('Starship Repository: Finding Starships'); + + return [ + new Starship( + 1, 'Starship 01', 'Heavy Starship', 'Human Captain', 'damaged', + ), + new Starship( + 2, 'Starship 02', 'Light Starship', 'Robot Captain', 'new', + ), + ]; + } +}