Skip to content

Commit 8de1070

Browse files
committed
feat(handler): Add handler for fetching individual app page
1 parent 6abe6b1 commit 8de1070

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/handler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ export async function getAppsPageHandler(req: Request, res: Response) {
5454
});
5555
}
5656

57+
// GET /apps/:id
58+
export async function getAppPageHandler(req: Request, res: Response) {
59+
const [app] = await db
60+
.select('*')
61+
.from('apps')
62+
.where({ id: parseInt(req.params.id!) });
63+
return res.render('apps-id.html', {
64+
app,
65+
layout: '../layouts/auth.html',
66+
});
67+
}
68+
5769
// GET /apps/create
5870
export async function getCreateNewAppPageHandler(req: Request, res: Response) {
5971
return res.render('apps-create.html', {

src/router.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
postNotificationHandler,
44
getHomePageHandler,
55
getAppsPageHandler,
6+
getAppPageHandler,
67
getTermsOfServicePageHandler,
78
getSettingsPageHandler,
89
getProfilePageHandler,
@@ -28,6 +29,8 @@ router.get('/apps', catchAsyncErrorMiddleware(getAppsPageHandler));
2829

2930
router.get('/apps/create', catchAsyncErrorMiddleware(getCreateNewAppPageHandler));
3031

32+
router.get('/apps/:id', catchAsyncErrorMiddleware(getAppPageHandler));
33+
3134
router.get('/settings', catchAsyncErrorMiddleware(getSettingsPageHandler));
3235

3336
router.get('/profile', catchAsyncErrorMiddleware(getProfilePageHandler));

src/views/pages/apps-id.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="p-10">
2+
<div class="mx-auto max-w-6xl w-full prose">
3+
<h2>Apps / <%= app.id %></h2>
4+
<pre><%= JSON.stringify(app, null, 2) %></pre>
5+
</div>
6+
</div>

src/views/pages/apps.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h2 class="mt-0">Apps</h2>
1010
<% if (apps.length) { %>
1111
<% apps.forEach(app => { %>
1212
<div class="p-5 border border-gray-100 rounded-md bg-base-100">
13-
<h4><%= app.name %></h4>
13+
<a class="link" href="/apps/<%= app.id %>"><h4><%= app.name %></h4></a>
1414
</div>
1515
<% }) %>
1616
<% } %>

0 commit comments

Comments
 (0)