Installed and used composer require symfony/http-client and printing Iss location data on homepage.

This commit is contained in:
Krzysztof Płaczek
2024-10-19 18:01:18 +02:00
parent 6172d76b79
commit d44091fe6e
4 changed files with 18 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
"symfony/dotenv": "7.1.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "7.1.*",
"symfony/http-client": "7.1.*",
"symfony/monolog-bundle": "^3.0",
"symfony/property-access": "7.1.*",
"symfony/property-info": "7.1.*",

2
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9adfba642a39cd4247f2862fcd13dded",
"content-hash": "c7be214a8ecb0ad6557710f0b209e737",
"packages": [
{
"name": "composer/semver",

View File

@@ -6,15 +6,21 @@ use App\Repository\StarshipRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class MainController extends AbstractController
{
#[Route('/', name: 'app_homepage')]
public function homepage(StarshipRepository $repository): Response
public function homepage(
HttpClientInterface $client,
StarshipRepository $repository): Response
{
$starships = $repository->findAll();
$starship = $starships[array_rand($starships)];
return $this->render('main/homepage.html.twig', ['ships' => $starships, 'myShip' => $starship]);
$response = $client->request('GET', 'https://api.wheretheiss.at/v1/satellites/25544');
$issData = $response->toArray();
return $this->render('main/homepage.html.twig', ['ships' => $starships, 'myShip' => $starship, 'issData' => $issData]);
}
}

View File

@@ -52,6 +52,14 @@
Looking for your next galactic ride?
<a href="#" class="underline font-semibold">Browse the {{ ships|length * 10 }} starships for sale!</a>
</p>
<div>
<h2 class="text-4xl font-semibold my-8">ISS Location</h2>
<p>Time: {{ issData.timestamp|date }}</p>
<p>Altitude: {{ issData.altitude }}</p>
<p>Latitude: {{ issData.latitude }}</p>
<p>Longitude: {{ issData.longitude }}</p>
<p>Visibility: {{ issData.visibility }}</p>
</div>
</div>
</main>
{% endblock %}