Installed and used composer require symfony/http-client and printing Iss location data on homepage.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
"symfony/dotenv": "7.1.*",
|
"symfony/dotenv": "7.1.*",
|
||||||
"symfony/flex": "^2",
|
"symfony/flex": "^2",
|
||||||
"symfony/framework-bundle": "7.1.*",
|
"symfony/framework-bundle": "7.1.*",
|
||||||
|
"symfony/http-client": "7.1.*",
|
||||||
"symfony/monolog-bundle": "^3.0",
|
"symfony/monolog-bundle": "^3.0",
|
||||||
"symfony/property-access": "7.1.*",
|
"symfony/property-access": "7.1.*",
|
||||||
"symfony/property-info": "7.1.*",
|
"symfony/property-info": "7.1.*",
|
||||||
|
|||||||
2
composer.lock
generated
2
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "9adfba642a39cd4247f2862fcd13dded",
|
"content-hash": "c7be214a8ecb0ad6557710f0b209e737",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "composer/semver",
|
"name": "composer/semver",
|
||||||
|
|||||||
@@ -6,15 +6,21 @@ use App\Repository\StarshipRepository;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
class MainController extends AbstractController
|
class MainController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/', name: 'app_homepage')]
|
#[Route('/', name: 'app_homepage')]
|
||||||
public function homepage(StarshipRepository $repository): Response
|
public function homepage(
|
||||||
|
HttpClientInterface $client,
|
||||||
|
StarshipRepository $repository): Response
|
||||||
{
|
{
|
||||||
$starships = $repository->findAll();
|
$starships = $repository->findAll();
|
||||||
$starship = $starships[array_rand($starships)];
|
$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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,14 @@
|
|||||||
Looking for your next galactic ride?
|
Looking for your next galactic ride?
|
||||||
<a href="#" class="underline font-semibold">Browse the {{ ships|length * 10 }} starships for sale!</a>
|
<a href="#" class="underline font-semibold">Browse the {{ ships|length * 10 }} starships for sale!</a>
|
||||||
</p>
|
</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>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user