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
1bf5121c
Commit
1bf5121c
authored
2 months ago
by
65160394
Browse files
Options
Downloads
Patches
Plain Diff
Project Round 2
parent
4656386f
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
+19
-16
19 additions, 16 deletions
controllers/tourController.js
routes/tourRoutes.js
+4
-3
4 additions, 3 deletions
routes/tourRoutes.js
views/index.ejs
+22
-18
22 additions, 18 deletions
views/index.ejs
with
45 additions
and
37 deletions
controllers/tourController.js
+
19
−
16
View file @
1bf5121c
const
Tour
=
require
(
'
../
models/tourModel
'
);
const
db
=
require
(
'
../
config/db
'
);
exports
.
getTours
=
async
(
req
,
res
)
=>
{
class
Tour
{
static
async
getAllTours
()
{
try
{
try
{
const
tours
=
await
Tour
.
getAllT
ours
(
);
const
[
rows
]
=
await
db
.
query
(
'
SELECT * FROM t
ours
'
);
res
.
render
(
'
index
'
,
{
tours
})
;
return
rows
;
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
เกิดข้อผิดพลาด
'
);
throw
error
;
}
}
}
};
exports
.
getTourDetails
=
async
(
req
,
res
)
=>
{
static
async
getTourById
(
id
)
{
try
{
try
{
const
tour
=
await
Tour
.
getTourById
(
req
.
params
.
id
);
const
[
rows
]
=
await
db
.
query
(
'
SELECT * FROM tours WHERE id = ?
'
,
[
id
]);
if
(
!
tour
)
return
res
.
status
(
404
).
send
(
'
ไม่พบข้อมูล
'
);
return
rows
.
length
>
0
?
rows
[
0
]
:
null
;
res
.
render
(
'
tour-details
'
,
{
tour
});
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
เกิดข้อผิดพลาด
'
);
throw
error
;
}
}
}
};
}
module
.
exports
=
Tour
;
This diff is collapsed.
Click to expand it.
routes/tourRoutes.js
+
4
−
3
View file @
1bf5121c
const
express
=
require
(
'
express
'
);
const
express
=
require
(
'
express
'
);
const
{
getTours
,
getTourDetails
}
=
require
(
'
../controllers/tourController
'
);
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
const
tourController
=
require
(
'
../controllers/tourController
'
);
router
.
get
(
'
/
'
,
tourController
.
getTours
);
router
.
get
(
'
/
'
,
getTours
);
// แสดงรายการทัวร์ทั้งหมด
router
.
get
(
'
/tour/:id
'
,
tourController
.
getTourDetails
);
router
.
get
(
'
/tour/:id
'
,
getTourDetails
);
// แสดงรายละเอียดทัวร์ตาม id
module
.
exports
=
router
;
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
views/index.ejs
+
22
−
18
View file @
1bf5121c
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
</header>
</header>
<section
class=
"tour-list"
>
<section
class=
"tour-list"
>
<h2>
Available Tours
</h2>
<
%
if
(tours.length =
==
0)
{
%
>
<p>
No tours available at the moment. Please check back later.
</p>
<
%
}
else
{
%
>
<ul>
<ul>
<
%
tours.forEach(tour =
>
{
%
>
<
%
tours.forEach(tour =
>
{
%
>
<li
class=
"tour-card"
>
<li
class=
"tour-card"
>
...
@@ -37,6 +39,8 @@
...
@@ -37,6 +39,8 @@
</li>
</li>
<
%
})
%
>
<
%
})
%
>
</ul>
</ul>
<
%
}
%
>
</section>
</section>
<footer>
<footer>
...
...
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