From 1f2ffc7f8777bea678fe94e2f9b124db2947df01 Mon Sep 17 00:00:00 2001
From: Selma EL BABARTI <selma.el-babarti@etu.univ-nantes.fr>
Date: Sat, 20 May 2023 14:48:06 +0200
Subject: [PATCH] patchAPI et essai maj cuisine

---
 dynamique/app/js/admin.js    |  72 ++++++++++++++++++++++++++++++++++-
 dynamique/app/js/pays.js     |   2 +-
 dynamique/data/latinotrip.db | Bin 114688 -> 114688 bytes
 3 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/dynamique/app/js/admin.js b/dynamique/app/js/admin.js
index 7c0b02e..cc7879c 100644
--- a/dynamique/app/js/admin.js
+++ b/dynamique/app/js/admin.js
@@ -3,7 +3,7 @@ var pageUrl = window.location.pathname; // renvoie l'URL de la page
 var pageID = pageUrl.substring(pageUrl.lastIndexOf('/') + 1, pageUrl.lastIndexOf('.'));
 
 const base_url = 'http://127.0.0.1:8899';
-const auth_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNlbG1hLmVsYmFiYXJ0aUBnbWFpbC5jb20iLCJmaXJzdG5hbWUiOm51bGwsImxhc3RuYW1lIjpudWxsLCJpZCI6InVzX2g0bTBxM2VnNDM0eGJ4Iiwicm9sZXMiOiJvcmctbGV2ZWwtY3JlYXRvcixzdXBlciIsInRva2VuX3ZlcnNpb24iOiI4YmIwMjBjYjQ5YmVjMjJlOGQzNGY4YjkzOGQ2NDc4OTczYWY4ZTFlZDBiZjIxNzQ0YzFkNzliMGM2MGY2ZjAzMGEwYTI3OWFhY2VlMzk4YSIsImlhdCI6MTY4NDQyMzk5NywiZXhwIjoxNjg0NDU5OTk3fQ.liSM1MtILIxu7ZNFilbC7BraHH6hV7EwRJtRrviQjkA';
+const auth_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNlbG1hLmVsYmFiYXJ0aUBnbWFpbC5jb20iLCJmaXJzdG5hbWUiOm51bGwsImxhc3RuYW1lIjpudWxsLCJpZCI6InVzX2g0bTBxM2VnNDM0eGJ4Iiwicm9sZXMiOiJvcmctbGV2ZWwtY3JlYXRvcixzdXBlciIsInRva2VuX3ZlcnNpb24iOiI4YmIwMjBjYjQ5YmVjMjJlOGQzNGY4YjkzOGQ2NDc4OTczYWY4ZTFlZDBiZjIxNzQ0YzFkNzliMGM2MGY2ZjAzMGEwYTI3OWFhY2VlMzk4YSIsImlhdCI6MTY4NDU3ODU1MywiZXhwIjoxNjg0NjE0NTUzfQ.81PRDL-9EwzVoq5imk7g0nVr5AYi7GHtJO5kp62dKB8';
 
 async function getFromAPI(url) {
   let req = await fetch(url, {
@@ -24,6 +24,26 @@ async function getFromAPI(url) {
   }
 }
 
+async function patchAPI(url, data) {
+  const requestOptions = {
+    method: 'PATCH',
+    headers: {
+      'Content-Type': 'application/json',
+      'xc-auth': auth_token
+    },
+    body: JSON.stringify(data)
+  };
+
+  const response = await fetch(url, requestOptions);
+
+  if (response.ok) {
+    const responseData = await response.json();
+    return responseData;
+  } else {
+    throw new Error('Erreur lors de la requête PATCH API');
+  }
+}
+
 // ...
 
 // Fonction pour pré-remplir les informations du pays sélectionné
@@ -168,6 +188,42 @@ loadOptions();
 
 // ...
 
+
+
+
+
+
+
+
+
+
+
+
+// Fonction pour mettre à jour la liste de cuisines d'un pays
+async function updateCountryListForCuisine(cuisineId, countryIds) {
+  try {
+    // Récupérer les données de la cuisine à partir de l'API
+    const cuisineData = await getFromAPI(`/api/v1/db/data/v1/Latino/Cuisine/${cuisineId}`);
+    console.log('cuisinedata:',cuisineData)
+    const cuisine = cuisineData.data;
+    console.log('cuisine:', cuisine)
+
+    // Mettre à jour la liste des pays de la cuisine
+    cuisine['Pays List'] = countryIds;
+
+    // Mettre à jour la cuisine dans la base de données via l'API
+    const updatedCuisine = await patchAPI(`/api/v1/db/data/v1/Latino/Cuisine/${cuisineId}`, cuisine);
+    console.log('Cuisine mise à jour:', updatedCuisine);
+  } catch (error) {
+    console.error('Erreur lors de la mise à jour de la cuisine:', error);
+  }
+}
+
+
+
+
+
+
 // Fonction pour sauvegarder les modifications effectuées par l'administrateur
 async function saveCountryInfo(event) {
   event.preventDefault(); // Empêche le rechargement de la page
@@ -232,6 +288,18 @@ async function saveCountryInfo(event) {
 
   console.log('Requête API:', url, requestOptions);
 
+
+
+
+  //....
+  // Mettre à jour la liste de pays dans chaque cuisine sélectionnée
+  selectedCuisineOptions.forEach(cuisineOption => {
+    updateCountryListForCuisine(cuisineOption.IdCuisine, [selectedCountryId]);
+  });
+  //....
+
+
+  
   const response = await fetch(url, requestOptions);
 
   if (response.ok) {
@@ -246,4 +314,4 @@ async function saveCountryInfo(event) {
 }
 
 var submitbutton = document.getElementById("submit");
-submitbutton.addEventListener("click", saveCountryInfo);
+submitbutton.addEventListener("click", saveCountryInfo);
\ No newline at end of file
diff --git a/dynamique/app/js/pays.js b/dynamique/app/js/pays.js
index 7aa255d..8072c82 100644
--- a/dynamique/app/js/pays.js
+++ b/dynamique/app/js/pays.js
@@ -51,7 +51,7 @@ var pageID = pageUrl.substring(pageUrl.lastIndexOf('/')+1, pageUrl.lastIndexOf('
 
 
 const base_url = 'http://127.0.0.1:8899';
-const auth_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNlbG1hLmVsYmFiYXJ0aUBnbWFpbC5jb20iLCJmaXJzdG5hbWUiOm51bGwsImxhc3RuYW1lIjpudWxsLCJpZCI6InVzX2g0bTBxM2VnNDM0eGJ4Iiwicm9sZXMiOiJvcmctbGV2ZWwtY3JlYXRvcixzdXBlciIsInRva2VuX3ZlcnNpb24iOiI4YmIwMjBjYjQ5YmVjMjJlOGQzNGY4YjkzOGQ2NDc4OTczYWY4ZTFlZDBiZjIxNzQ0YzFkNzliMGM2MGY2ZjAzMGEwYTI3OWFhY2VlMzk4YSIsImlhdCI6MTY4NDQyMzk5NywiZXhwIjoxNjg0NDU5OTk3fQ.liSM1MtILIxu7ZNFilbC7BraHH6hV7EwRJtRrviQjkA';
+const auth_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNlbG1hLmVsYmFiYXJ0aUBnbWFpbC5jb20iLCJmaXJzdG5hbWUiOm51bGwsImxhc3RuYW1lIjpudWxsLCJpZCI6InVzX2g0bTBxM2VnNDM0eGJ4Iiwicm9sZXMiOiJvcmctbGV2ZWwtY3JlYXRvcixzdXBlciIsInRva2VuX3ZlcnNpb24iOiI4YmIwMjBjYjQ5YmVjMjJlOGQzNGY4YjkzOGQ2NDc4OTczYWY4ZTFlZDBiZjIxNzQ0YzFkNzliMGM2MGY2ZjAzMGEwYTI3OWFhY2VlMzk4YSIsImlhdCI6MTY4NDU3ODU1MywiZXhwIjoxNjg0NjE0NTUzfQ.81PRDL-9EwzVoq5imk7g0nVr5AYi7GHtJO5kp62dKB8';
 
 async function getFromAPI( url ){
     let req = await fetch( url ,{
diff --git a/dynamique/data/latinotrip.db b/dynamique/data/latinotrip.db
index 3c4a7b154d7484ebff4e7d391aa605f7ce4a8252..866defe2d83ab0c06cc50e3c22d71bf9311cdcdb 100644
GIT binary patch
delta 162
zcmZo@U~gz(pCHXxHc`fzv20_)5_vvu{sj#DTlm-Wui{_IzhJX~LLWaX3o`>F_vEGe
ziCn7~SkLer<oM3CYU9FLOqy--ES#dEoyCpvjfTmkNr}!-tWc6#T%us8keZeOhN+vM
z2(4$@++^CsCB)8ghk>V$lZE3C#}|$_98WmzY+M+?x;f3YjG2Rtn~ebknxA-Vf8xO?
GQw{)e7&K-8

delta 159
zcmZo@U~gz(pCHYcF;T{uF=J!G5_t(O{-q53Tlm-Wui{_Ie~kYX|2O`-{8#vQZdN?d
z$v=64KFj2l`mtP_8CcKo9OU@Uw0Yyg#Y_rqVl14ZqMeD2@{NYcrAdj-P^?grT3n)F
zWVHE-(0ZoLO{Ps;0&E;l7<l?PSvdZ1eBpS*@nqw|AlA)ku4T*|76t}-Sp})-%}+eG
KKk;CcDF*<X$~g4^

-- 
GitLab