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 e0c7f02..a10b046 100644 --- a/routes.js +++ b/routes.js @@ -33,4 +33,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/graphique.ejs deleted file mode 100644 index 14b1815..0000000 --- a/views/graphique.ejs +++ /dev/null @@ -1,76 +0,0 @@ - - - - - Diagramme Radar avec Chart.js - - - -
- -
- - - - \ No newline at end of file