diff --git a/routes/tourRoutes.js b/routes/tourRoutes.js index c0fd9c3fdbff628ee273f9debbde88b5927874ba..bbe865b6f2f0bcf6cf7d9f134bb0dd094560d520 100644 --- a/routes/tourRoutes.js +++ b/routes/tourRoutes.js @@ -1,30 +1,10 @@ -// routes/tourRoutes.js const express = require('express'); const router = express.Router(); +const tourController = require('../controllers/tourController'); + +router.get('/', tourController.getTours); +router.get('/tour/:id', tourController.getTourDetails); -// ตัวอย่าง route สำหรับหน้าแสดงทัวร์ทั้งหมด -router.get('/tours', (req, res) => { - req.db.query('SELECT * FROM tours', (err, results) => { - if (err) { - return res.status(500).json({ error: 'Failed to fetch tours' }); - } - res.render('tours', { tours: results }); - }); -}); -// ตัวอย่าง route สำหรับหน้าแสดงรายละเอียดทัวร์ -router.get('/tour/:id', (req, res) => { - const tourId = req.params.id; - req.db.query('SELECT * FROM tours WHERE id = ?', [tourId], (err, results) => { - if (err) { - return res.status(500).json({ error: 'Failed to fetch tour details' }); - } - if (results.length > 0) { - res.render('tourDetail', { tour: results[0] }); - } else { - res.status(404).send('Tour not found'); - } - }); -}); module.exports = router;