tentavive page restos
This commit is contained in:
parent
f2ff5c1531
commit
d9c975ec2f
5 changed files with 62 additions and 6 deletions
BIN
database.sqlite
Normal file
BIN
database.sqlite
Normal file
Binary file not shown.
21
db_init.js
21
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;
|
||||
|
|
|
|||
20
routes.js
20
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;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
<script>
|
||||
const ctx = document.getElementById('radarChart').getContext('2d');
|
||||
const radarChart = new Chart(ctx, {
|
||||
type: 'radar',
|
||||
type: 'radar',S,
|
||||
data: {
|
||||
labels: ['Qualité des plats', 'Ambiance', 'Accessibilité', 'Service', 'Tradition'],
|
||||
datasets: [
|
||||
|
|
@ -21,12 +21,12 @@ const radarChart = new Chart(ctx, {
|
|||
label: 'Moyenne des notes',
|
||||
data: [4.7, 4.6, 4.4, 4.3, 4.8],
|
||||
fill: true,
|
||||
backgroundColor: 'rgba(25, 80, 233, 0.2)',
|
||||
borderColor: 'rgb(25, 80, 233, 10)',
|
||||
pointBackgroundColor: 'rgb(55, 99, 132)',
|
||||
backgroundColor: 'rgba(255, 215, 0, 0.2)',
|
||||
borderColor: 'rgb(255, 215, 0)',
|
||||
pointBackgroundColor: 'rgb(255, 215, 0)',
|
||||
pointBorderColor: '#fff',
|
||||
pointHoverBackgroundColor: '#fff',
|
||||
pointHoverBorderColor: 'rgb(255, 99, 132)',
|
||||
pointHoverBorderColor: 'rgb(255, 215, 0)',
|
||||
pointStyle: 'circle',
|
||||
pointRadius: 5,
|
||||
pointRotation: 0,
|
||||
17
views/infos.ejs
Normal file
17
views/infos.ejs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= restaurant.nom %></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= restaurant.nom %></h1>
|
||||
<p><%= restaurant.description %></p>
|
||||
<p>Adresse : <%= restaurant.adresse %></p>
|
||||
<h2>Menu</h2>
|
||||
<ul>
|
||||
<% restaurant.menu.forEach((plat) => { %>
|
||||
<li><%= plat %></li>
|
||||
<% }); %>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue