Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 1bf5121c authored by 65160394's avatar 65160394
Browse files

Project Round 2

parent 4656386f
No related branches found
No related tags found
No related merge requests found
const Tour = require('../models/tourModel'); const db = require('../config/db');
exports.getTours = async (req, res) => { class Tour {
static async getAllTours() {
try { try {
const tours = await Tour.getAllTours(); const [rows] = await db.query('SELECT * FROM tours');
res.render('index', { tours }); return rows;
} catch (error) { } catch (error) {
res.status(500).send('เกิดข้อผิดพลาด'); throw error;
}
} }
};
exports.getTourDetails = async (req, res) => { static async getTourById(id) {
try { try {
const tour = await Tour.getTourById(req.params.id); const [rows] = await db.query('SELECT * FROM tours WHERE id = ?', [id]);
if (!tour) return res.status(404).send('ไม่พบข้อมูล'); return rows.length > 0 ? rows[0] : null;
res.render('tour-details', { tour });
} catch (error) { } catch (error) {
res.status(500).send('เกิดข้อผิดพลาด'); throw error;
}
} }
}; }
module.exports = Tour;
const express = require('express'); const express = require('express');
const { getTours, getTourDetails } = require('../controllers/tourController');
const router = express.Router(); const router = express.Router();
const tourController = require('../controllers/tourController');
router.get('/', tourController.getTours); router.get('/', getTours); // แสดงรายการทัวร์ทั้งหมด
router.get('/tour/:id', tourController.getTourDetails); router.get('/tour/:id', getTourDetails); // แสดงรายละเอียดทัวร์ตาม id
module.exports = router; module.exports = router;
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
</header> </header>
<section class="tour-list"> <section class="tour-list">
<h2>Available Tours</h2> <% if (tours.length === 0) { %>
<p>No tours available at the moment. Please check back later.</p>
<% } else { %>
<ul> <ul>
<% tours.forEach(tour => { %> <% tours.forEach(tour => { %>
<li class="tour-card"> <li class="tour-card">
...@@ -37,6 +39,8 @@ ...@@ -37,6 +39,8 @@
</li> </li>
<% }) %> <% }) %>
</ul> </ul>
<% } %>
</section> </section>
<footer> <footer>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment