From d44091fe6efe44f2f0a373384b96955d27188c90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?=
Date: Sat, 19 Oct 2024 18:01:18 +0200
Subject: [PATCH] Installed and used `composer require symfony/http-client` and
printing Iss location data on homepage.
---
composer.json | 1 +
composer.lock | 2 +-
src/Controller/MainController.php | 10 ++++++++--
templates/main/homepage.html.twig | 8 ++++++++
4 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/composer.json b/composer.json
index dd94b12..1aa768b 100644
--- a/composer.json
+++ b/composer.json
@@ -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.*",
diff --git a/composer.lock b/composer.lock
index d56cc70..34776ef 100644
--- a/composer.lock
+++ b/composer.lock
@@ -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",
diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php
index 15eb07a..d58e768 100644
--- a/src/Controller/MainController.php
+++ b/src/Controller/MainController.php
@@ -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]);
}
}
diff --git a/templates/main/homepage.html.twig b/templates/main/homepage.html.twig
index aedc4b5..4ef18ac 100644
--- a/templates/main/homepage.html.twig
+++ b/templates/main/homepage.html.twig
@@ -52,6 +52,14 @@
Looking for your next galactic ride?
Browse the {{ ships|length * 10 }} starships for sale!
+
+
ISS Location
+
Time: {{ issData.timestamp|date }}
+
Altitude: {{ issData.altitude }}
+
Latitude: {{ issData.latitude }}
+
Longitude: {{ issData.longitude }}
+
Visibility: {{ issData.visibility }}
+
{% endblock %}