From 20be8fe5b8d95d2f1bf3577fa5054cef2d63fb27 Mon Sep 17 00:00:00 2001
From: Atiwit Pattanapukdee <65160394@go.buu.ac.th>
Date: Tue, 18 Mar 2025 23:32:23 +0700
Subject: [PATCH] Project Round 6

---
 controllers/tourController.js | 10 ++++++++--
 views/search.ejs              |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/controllers/tourController.js b/controllers/tourController.js
index 48091bc..e9325a9 100644
--- a/controllers/tourController.js
+++ b/controllers/tourController.js
@@ -209,13 +209,19 @@ exports.postCreateTour = async (req, res) => {
     }
 };
 
-//ค้นหาทัวร์
+// ค้นหาทัวร์
 exports.searchTours = async (req, res) => {
   try {
     const searchQuery = req.query.query;
     const tours = await Tour.searchTours(searchQuery);
+
+    // หากไม่พบทัวร์จากการค้นหา
+    if (tours.length === 0) {
+      return res.render('search', { tours: [], message: 'ไม่พบที่ค้นหา' });
+    }
+
     res.render('search', { tours, session: req.session });
   } catch (error) {
     res.status(500).send("Error searching tours");
   }
-};
\ No newline at end of file
+};
diff --git a/views/search.ejs b/views/search.ejs
index b4eb489..ec60cf8 100644
--- a/views/search.ejs
+++ b/views/search.ejs
@@ -9,7 +9,7 @@
       </li>
     <% }) %>
   <% } else { %>
-    <p>No tours found</p>
+    <p>ไม่พบทัวร์ที่ค้นหา</p>
   <% } %>
 </ul>
 
-- 
GitLab