From dfda73b0701035cfda69c27b5d1269d1ae5c7c3b Mon Sep 17 00:00:00 2001 From: sinbad Date: Mon, 8 Apr 2024 09:01:14 +0200 Subject: [PATCH] Almost end back + start front but missing topbar for test --- src/API/requests.php | 20 +++++++++++++ src/API/src/response.php | 9 ++++++ src/API/test/database.php | 60 +++++++++++++++++++++++++++++++++----- src/js/AJAX/index.js | 61 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 141 insertions(+), 9 deletions(-) diff --git a/src/API/requests.php b/src/API/requests.php index a581b1f..fe8e52d 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -67,8 +67,28 @@ $router->DELETE('/api/requests', ["test"], function($test){ $router->GET('/api/rdv-praticient', ["id"], function($id){ global $pdo; dbRequestRdvPraticien($pdo, $id); + getAllLieux($pdo); }); +$router->GET('/api/rdv-patient', ["id"], function($id){ + global $pdo; + dbRequestRdvPatient($pdo, $id); + getPastRdvByPatient($pdo, $id); +}); +$router->DELETE('/api/delete-empty', ["id"], function($id){ + global $pdo; + DeleteEmptyRdv($pdo, $id); +}); + +$router->DELETE('/api/cancel-rdv', ["id"], function($id){ + global $pdo; + CancelRDV($pdo, $id); +}); + +$router->POST('/api/create-rdv', ["id", "date", "time", "lieu"], function($id, $date, $time, $lieu){ + global $pdo; + createRDV($pdo, $id, $date, $time, $lieu); +}); $router->run(); diff --git a/src/API/src/response.php b/src/API/src/response.php index 12cfd0d..7df29d5 100644 --- a/src/API/src/response.php +++ b/src/API/src/response.php @@ -38,6 +38,15 @@ class Response echo json_encode($data); } + public static function HTTP403($data): void + { + header('Content-Type: application/json; charset=utf-8'); + header('Cache-control: no-store, no-cache, must-revalidate'); + header('Pragma: no-cache'); + http_response_code(403); + echo json_encode($data); + } + static function HTTP404($data): void { header('Content-Type: application/json; charset=utf-8'); diff --git a/src/API/test/database.php b/src/API/test/database.php index a211b81..4c3447d 100644 --- a/src/API/test/database.php +++ b/src/API/test/database.php @@ -40,6 +40,49 @@ function dbRequestRdvPraticien($pdo, $id){ } +function dbRequestRdvPatient($pdo, $id){ + $statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty, medecin.m_id, concat(p_name, ' ', p_surname) as patient, l_adress as adresse, concat(l_postal, ' ', l_city) as ville + FROM rendez_vous + INNER JOIN patient ON rendez_vous.p_id = patient.p_id + INNER JOIN propose ON rendez_vous.rdv_id = propose.rdv_id + INNER JOIN medecin ON propose.m_id = medecin.m_id + INNER JOIN lieu on lieu.l_id = rendez_vous.l_id + + WHERE NOW() <= (rdv_date + rdv_time) AND patient.p_id = :id + ORDER BY rdv_date, rdv_time ASC"); + + $statement->bindParam(':id', $id); + $statement->execute(); + $result = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!empty($result)) { + Response::HTTP200($result); + } else { + Response::HTTP404(["error" => "No data found"]); + } +} + +function getPastRdvByPatient($pdo, $id){ + $statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty, medecin.m_id, concat(p_name, ' ', p_surname) as patient, l_adress as adresse, concat(l_postal, ' ', l_city) as ville + FROM rendez_vous + INNER JOIN patient ON rendez_vous.p_id = patient.p_id + INNER JOIN propose ON rendez_vous.rdv_id = propose.rdv_id + INNER JOIN medecin ON propose.m_id = medecin.m_id + INNER JOIN lieu on lieu.l_id = rendez_vous.l_id + + WHERE NOW() > (rdv_date + rdv_time) AND patient.p_id = :id + ORDER BY rdv_date, rdv_time ASC"); + $statement->bindParam(':id', $id); + $statement->execute(); + $result = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!empty($result)) { + Response::HTTP200($result); + } else { + Response::HTTP404(["error" => "No data found"]); + } +} + function getLieuID($pdo, $adress, $postal, $city){ $statement = $pdo->prepare("SELECT l_id FROM lieu WHERE l_adress = :adress AND l_city = :city AND l_postal = :postal"); $statement->bindParam(':adress', $adress); @@ -61,9 +104,9 @@ function getAllLieux($pdo){ $result = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($result)) { - return $result; + Response::HTTP200($result); } else { - return null; + Response::HTTP404(["error" => "No data found"]); } } @@ -86,21 +129,22 @@ function CreateRDV($pdo, $medID, $date, $time, $lieu){ $statement->bindParam(':medID', $medID); $statement->bindParam(':rdvID', $rdvID); $statement->execute(); - return true; + Response::HTTP200(["Success" => "RDV created"]); } - return false; + Response::HTTP404(["Error" => "Lieu not found"]); } -function DeleteEmptyRdv($pdo, $id){ +function DeleteEmptyRdv($pdo, $id) +{ $statement = $pdo->prepare("SELECT p_id FROM rendez_vous WHERE rdv_id = :id"); $statement->bindParam(':id', $id); $statement->execute(); $result = $statement->fetch(PDO::FETCH_ASSOC); - if($result['p_id'] == null){ + if ($result['p_id'] == null) { $statement = $pdo->prepare("DELETE FROM rendez_vous WHERE rdv_id = :id"); $statement->bindParam(':id', $id); $statement->execute(); - return true; + Response::HTTP200(["Success" => "RDV deleted"]); } - return false; + Response::HTTP403(["Forbidden" => "This RDV is not empty"]); } \ No newline at end of file diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index ee3b598..c504dff 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -1,5 +1,7 @@ console.log("index.js loaded"); +//Felix Part + function displaySearchResults(data) { let container = document.getElementById("content"); container.innerHTML = ""; @@ -213,4 +215,61 @@ function attachRDVEventListener() { }); } -attachSearchEventListener(); \ No newline at end of file +//Yanis Part + +function DisplayRDVPraticient(rdv){ + let count = rdv.length; + $('#content').empty(); + $('#content').html('
'); + if(count === 0){ + $('#content').append('

Vous n\'avez pas de rendez-vous

'); + } + else { + for (let i = 0; i < count; i++){ + if (rdv[i].p_mail !== "null") + $('#content').append('' + + '
' + + '
' + + '
' + + '

' + rdv[i].rdv_date + '

' + + '

' + rdv[i].rdv_time + '

' + + '
' + '
' + + '
' + + '
' + rdv[i].patient + '
' + + '' + rdv[i].email + '' + + '
' + + '' + '0' + rdv[i].phone + '' + + '
' + '
'); + else{ + $('#content').append('' + + '
' + + '
' + + '
' + + '

' + rdv[i].rdv_date + '

' + + '

' + rdv[i].rdv_time + '

' + + '
' + '
' + + '
' + + '
Vous n\'avez pas de' + '
' + 'patient pour ce créneau
' + + '
' + '
'); + } + + } + } +} + +function ButtonShowRdvPraticient() { + document.getElementById("CalendarPraticient").addEventListener("click", function () { + ajaxRequest('GET', "src/API/requests.php/api/rdv-praticient?id=" + id, function (data) { + DisplayRDVPraticient(data); + }); + }); +} + + + + + +//End Call + +attachSearchEventListener(); +ButtonShowRdvPraticient(); \ No newline at end of file