Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160394
Project
Commits
4b707dd4
Commit
4b707dd4
authored
3 months ago
by
65160394
Browse files
Options
Downloads
Patches
Plain Diff
Project Round 9
parent
069960b7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
controllers/tourController.js
+8
-8
8 additions, 8 deletions
controllers/tourController.js
public/css/booklist.css
+55
-0
55 additions, 0 deletions
public/css/booklist.css
views/bookinglist.ejs
+4
-3
4 additions, 3 deletions
views/bookinglist.ejs
with
67 additions
and
11 deletions
controllers/tourController.js
+
8
−
8
View file @
4b707dd4
...
@@ -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
(
'
/log
in
'
);
// ถ้าไม่ได้ล็อกอิน ให้ไปหน้า login
}
}
try
{
try
{
// ดึงข้อมูลการจองของผู้ใช้จากฐานข้อมูล
const
query
=
`
const
query
=
`
SELECT b.id, t.name AS tour_name,
t.price, b.booking_dat
e
SELECT b.id
AS booking_id
, t.name AS tour_name,
b.status, u.name AS user_nam
e
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
(
'
b
ooking
list
'
,
{
bookings
});
res
.
render
(
'
myB
ooking
s
'
,
{
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
(
'
เกิดข้อผิดพลาดในการดึงข้อมูลการจอง
'
);
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
public/css/booklist.css
0 → 100644
+
55
−
0
View file @
4b707dd4
/* 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
;
}
}
This diff is collapsed.
Click to expand it.
views/bookinglist.ejs
+
4
−
3
View file @
4b707dd4
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment