commit 59da5643e459c44c30beceb74501ee2151a9cec3
parent 8acfbd9d7474619066b38acda43e6c93064ecc30
Author: DennyVB <[email protected]>
Date: Tue, 27 Jun 2023 12:04:54 +0200
Begin van onze prachtige API
Diffstat:
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/api/request.php b/api/request.php
@@ -0,0 +1,46 @@
+<?php
+
+$servername = "86.92.67.21";
+$username = "friedel";
+$password = "hailiwa";
+$dbname = "wap2";
+
+$mysqli = mysqli_connect($servername, $username, $password, $dbname);
+
+if (!$mysqli) {
+ die("Connection failed: " . mysqli_connect_error());
+}
+
+
+if (!isset($_SERVER['KEY'])) {
+ http_response_code(400);
+ echo 'Key not provided';
+ exit();
+}
+
+
+
+
+$key = $_SERVER['KEY'];
+
+$keyStatement = "SELECT distinct temperature, wind_speed, dew_point, DATE(date_time) AS date, nl.name as city
+ FROM weather_data wd
+ JOIN station s ON wd.station_name = s.name
+ JOIN contract_station cs ON cs.station_name = s.name
+ JOIN nearestlocation nl ON nl.station_name = s.name
+ JOIN country co ON co.country_code = nl.country_code
+ JOIN geolocation geo ON geo.country_code = co.country_code
+ JOIN contract c ON cs.contract_id = c.contract_id
+ WHERE c.token = ?
+ ORDER BY date DESC, temperature, wind_speed
+ ";
+
+$stmt = $mysqli->prepare($keyStatement);
+$stmt->bind_param("s", $key);
+$stmt->execute();
+$result = $stmt->get_result();
+$row = $result->fetch_all(MYSQLI_ASSOC);
+
+echo json_encode($row);
+
+
diff --git a/index.php b/index.php
@@ -13,6 +13,8 @@ $router->addRoute(['GET', 'POST'], '/add_contract', 'views/add_contract.php');
//add customer
$router->addRoute(['GET', 'POST'], '/add_customer', 'views/add_customer.php');
+$router->addRoute(['GET', 'POST'], '/request/api', 'api/request.php');
+
//add user
$router->addRoute(['GET', 'POST'], '/add_user', 'views/add_user.php');