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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160394
Project
Commits
e90177aa
Commit
e90177aa
authored
3 months ago
by
65160394
Browse files
Options
Downloads
Patches
Plain Diff
Project Round 3
parent
ee196aa4
Branches
Branches containing commit
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
+16
-16
16 additions, 16 deletions
controllers/tourController.js
models/tourModel.js
+25
-25
25 additions, 25 deletions
models/tourModel.js
routes/tourRoutes.js
+2
-2
2 additions, 2 deletions
routes/tourRoutes.js
with
43 additions
and
43 deletions
controllers/tourController.js
+
16
−
16
View file @
e90177aa
const
{
User
,
Tour
}
=
require
(
'
../models/tourModel
'
);
//
exports.getTours = async (req, res) => {
//
try {
//
const tours = await Tour.getAllTours();
//
res.render('index', { tours,session: req.session });
//
} catch (error) {
//
res.status(500).send(error.message);
//
}
//
};
//
exports.getTourDetails = async (req, res) => {
//
try {
//
const tour = await Tour.getTourById(req.params.id);
//
res.render('tour-details', { tour });
//
} catch (error) {
//
res.status(500).send(error.message);
//
}
//
};
exports
.
getTours
=
async
(
req
,
res
)
=>
{
try
{
const
tours
=
await
Tour
.
getAllTours
();
res
.
render
(
'
index
'
,
{
tours
,
session
:
req
.
session
});
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
error
.
message
);
}
};
exports
.
getTourDetails
=
async
(
req
,
res
)
=>
{
try
{
const
tour
=
await
Tour
.
getTourById
(
req
.
params
.
id
);
res
.
render
(
'
tour-details
'
,
{
tour
});
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
error
.
message
);
}
};
//User//
exports
.
getLogin
=
(
req
,
res
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
models/tourModel.js
+
25
−
25
View file @
e90177aa
const
pool
=
require
(
'
../config/database
'
);
const
bcrypt
=
require
(
'
bcryptjs
'
);
class
Tour
{
//
//
ดึงทัวร์ทั้งหมด
//
static async getAllTours() {
//
try {
//
console.log('Fetching all tours...');
//
const [rows] = await pool.query('SELECT * FROM tours');
//
console.log('Tours fetched successfully:', rows);
//
return rows;
//
} catch (error) {
//
console.error('Error fetching tours:', error.message);
//
throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์: ' + error.message);
//
}
//
}
// ดึงทัวร์ทั้งหมด
static
async
getAllTours
()
{
try
{
console
.
log
(
'
Fetching all tours...
'
);
const
[
rows
]
=
await
pool
.
query
(
'
SELECT * FROM tours
'
);
console
.
log
(
'
Tours fetched successfully:
'
,
rows
);
return
rows
;
}
catch
(
error
)
{
console
.
error
(
'
Error fetching tours:
'
,
error
.
message
);
throw
new
Error
(
'
เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์:
'
+
error
.
message
);
}
}
//
//
ดึงทัวร์ตาม ID
//
static async getTourById(id) {
//
try {
//
const [rows] = await pool.query('SELECT * FROM tours WHERE id = ?', [id]);
//
if (rows.length === 0) {
//
throw new Error('ไม่พบทัวร์ที่มี ID นี้');
//
}
//
return rows[0];
//
} catch (error) {
//
console.error('Error fetching tour by ID:', error);
//
throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์');
//
}
//
}
// ดึงทัวร์ตาม ID
static
async
getTourById
(
id
)
{
try
{
const
[
rows
]
=
await
pool
.
query
(
'
SELECT * FROM tours WHERE id = ?
'
,
[
id
]);
if
(
rows
.
length
===
0
)
{
throw
new
Error
(
'
ไม่พบทัวร์ที่มี ID นี้
'
);
}
return
rows
[
0
];
}
catch
(
error
)
{
console
.
error
(
'
Error fetching tour by ID:
'
,
error
);
throw
new
Error
(
'
เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์
'
);
}
}
// สร้างทัวร์
static
async
createTour
(
tourData
)
{
...
...
This diff is collapsed.
Click to expand it.
routes/tourRoutes.js
+
2
−
2
View file @
e90177aa
...
...
@@ -14,7 +14,7 @@ router.post('/login', tourController.postLogin); // ฟอร์มเข้า
router
.
get
(
'
/logout
'
,
tourController
.
Logout
);
// ออกจากระบบ
// สร้างทัวร์
router
.
get
(
'
/
tour/
create
'
,
tourController
.
getCreateTour
);
// หน้าสร้างทัวร์
router
.
post
(
'
/
tour/
create
'
,
tourController
.
createTour
);
// เพิ่ม route สำหรับการสร้างทัวร์โดยการ POST
router
.
get
(
'
/create
'
,
tourController
.
getCreateTour
);
// หน้าสร้างทัวร์
router
.
post
(
'
/create
'
,
tourController
.
createTour
);
// เพิ่ม route สำหรับการสร้างทัวร์โดยการ POST
module
.
exports
=
router
;
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