From d9c975ec2f8169ee21bfb3b436fe291efcfb800e Mon Sep 17 00:00:00 2001 From: DarkMax31 Date: Fri, 29 Aug 2025 09:52:42 +0200 Subject: [PATCH] tentavive page restos --- database.sqlite | Bin 0 -> 12288 bytes db_init.js | 21 +++++++++++++++++++++ routes.js | 20 +++++++++++++++++++- views/{graphique.ejs => index.ejs} | 10 +++++----- views/infos.ejs | 17 +++++++++++++++++ 5 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 database.sqlite rename views/{graphique.ejs => index.ejs} (88%) create mode 100644 views/infos.ejs diff --git a/database.sqlite b/database.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..61023b0a54dedee6f17c45ec586823cbf42e8456 GIT binary patch literal 12288 zcmeI#%SyyB6b9g=ips!TcHL&_fC%DRv}y#giq;M|s}gM-0=;OOk=crG;`{gl^CT{9 zA{`1Yire8okc5+*w9VI5?(afnBzrD(E(|*)BSI-TVT=$$>$Xw1CTzahB=uA7XYJU0w&#lwI-ZUTfKIC`2w@QF|d()l;d{q}hMY zFM>%Jvztj6w(DkPIm={cnSGpAxhjMy^`DoCH(|u@^y=HjV{gkp@+nb8Di_sjR^RLs zF*l{l6L-?&zzz0Zzhgc7wj0?F0Rad=00Izz00bZa0SG_<0uX?}x(f8{!Epay*WZhC YK>z{}fB*y_009U<00Izz00f-C51idtcmMzZ literal 0 HcmV?d00001 diff --git a/db_init.js b/db_init.js index 163ea5c..b7d3002 100644 --- a/db_init.js +++ b/db_init.js @@ -22,4 +22,25 @@ function initDb(dbPath = './database.sqlite') { }); } +function initDb (dbPath = './database.sqlite') { + return new Promise((resolve, reject) => { + const db = new sqlite3.Database(dbPath, (err) => { + if (err) { + reject(err); + } else { + db.run(` + CREATE TABLE IF NOT EXISTS restaurants ( + id INTEGER PRIMARY KEY, + nom TEXT NOT NULL, + description TEXT, + adresse TEXT NOT NULL, + menu TEXT + ); + `); + } + db.close(); + resolve(); + }); + }); +}; module.exports = initDb; diff --git a/routes.js b/routes.js index 937bb6d..1dc5be1 100644 --- a/routes.js +++ b/routes.js @@ -28,4 +28,22 @@ router.get('/logout', (req, res) => { }); }); -module.exports = router; + + +// Infos resto +router.get('/restaurants/:id', async (req, res) => { + const id = req.params.id; + try { + const restaurant = await db.get(`SELECT * FROM restaurants WHERE id = ?`, [id]); + if (!restaurant) { + res.status(404).send('Restaurant non trouvé'); + } else { + res.render('restaurant', { restaurant }); + } + } catch (err) { + console.error(err); + res.status(500).send('Erreur lors de la récupération des informations du restaurant'); + } +}); + +module.exports = router; \ No newline at end of file diff --git a/views/graphique.ejs b/views/index.ejs similarity index 88% rename from views/graphique.ejs rename to views/index.ejs index 14b1815..e86d80a 100644 --- a/views/graphique.ejs +++ b/views/index.ejs @@ -13,7 +13,7 @@