Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 4b707dd4 authored by 65160394's avatar 65160394
Browse files

Project Round 9

parent 069960b7
No related branches found
No related tags found
No related merge requests found
...@@ -283,29 +283,29 @@ exports.getAllTours = async (req, res) => { ...@@ -283,29 +283,29 @@ exports.getAllTours = async (req, res) => {
} }
}; };
// ดึงข้อมูลการจองพร้อมชื่อผู้จอง
exports.getUserBookings = async (req, res) => { exports.getUserBookings = async (req, res) => {
const userId = req.session.userId; // ตรวจสอบการใช้งาน session สำหรับ userId const userId = req.session.userId; // สมมติว่าใช้ session สำหรับจัดการผู้ใช้
// ตรวจสอบว่า userId ถูกต้องหรือไม่
if (!userId) { if (!userId) {
return res.status(400).send('User not logged in.'); return res.redirect('/login'); // ถ้าไม่ได้ล็อกอิน ให้ไปหน้า login
} }
try { try {
// ดึงข้อมูลการจองของผู้ใช้จากฐานข้อมูล
const query = ` const query = `
SELECT b.id, t.name AS tour_name, t.price, b.booking_date SELECT b.id AS booking_id, t.name AS tour_name, b.status, u.name AS user_name
FROM bookings b FROM bookings b
JOIN tours t ON b.tour_id = t.id JOIN tours t ON b.tour_id = t.id
JOIN users u ON b.user_id = u.id
WHERE b.user_id = ? WHERE b.user_id = ?
ORDER BY b.booking_date DESC ORDER BY b.booking_date DESC
`; `;
const [bookings] = await pool.query(query, [userId]); const [bookings] = await pool.query(query, [userId]);
// ส่งข้อมูลการจองกลับไปยังผู้ใช้ // ส่งข้อมูลการจองไปยังหน้า EJS
res.render('bookinglist', { bookings }); res.render('myBookings', { bookings: bookings });
} catch (error) { } catch (error) {
console.error('Error fetching user bookings:', error.message); console.error('Error fetching bookings:', error.message);
res.status(500).send('เกิดข้อผิดพลาดในการดึงข้อมูลการจอง'); res.status(500).send('เกิดข้อผิดพลาดในการดึงข้อมูลการจอง');
} }
}; };
......
/* booking.css */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 20px;
padding: 0;
text-align: center;
}
h1 {
color: #333;
margin-bottom: 20px;
}
table {
width: 80%;
margin: 0 auto;
border-collapse: collapse;
background-color: white;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
}
th, td {
padding: 12px;
border: 1px solid #ddd;
text-align: center;
}
th {
background-color: #007bff;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
cursor: pointer;
}
/* Responsive */
@media (max-width: 768px) {
table {
width: 100%;
}
th, td {
padding: 8px;
font-size: 14px;
}
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Bookings</title> <title>My Bookings</title>
<link rel="stylesheet" href="/css/booklist.css">
</head> </head>
<body> <body>
<h1>Your Bookings</h1> <h1>Your Bookings</h1>
...@@ -11,16 +12,16 @@ ...@@ -11,16 +12,16 @@
<thead> <thead>
<tr> <tr>
<th>Booking ID</th> <th>Booking ID</th>
<th>Booking User</th>
<th>Tour Title</th> <th>Tour Title</th>
<th>Status</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% bookings.forEach(booking => { %> <% bookings.forEach(booking => { %>
<tr> <tr>
<td><%= booking.id %></td> <!-- booking_id --> <td><%= booking.id %></td> <!-- booking_id -->
<td><%= booking.user_name %></td> <!-- ชื่อผู้จอง -->
<td><%= booking.tour_name %></td> <!-- tour_title --> <td><%= booking.tour_name %></td> <!-- tour_title -->
<td><%= booking.status %></td>
</tr> </tr>
<% }) %> <% }) %>
</tbody> </tbody>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment