File tree Expand file tree Collapse file tree 6 files changed +19
-8
lines changed
Expand file tree Collapse file tree 6 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1+ ALTER TABLE posts ADD COLUMN created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL ;
2+ CREATE INDEX posts_created_at_index ON posts (created_at);
Original file line number Diff line number Diff line change 22CREATE TABLE posts (
33 id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL ,
44 title TEXT NOT NULL ,
5- body TEXT NOT NULL
5+ body TEXT NOT NULL ,
6+ created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
67);
8+ CREATE INDEX posts_created_at_index ON posts (created_at);
Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ import Web.View.Posts.Show
88
99instance Controller PostsController where
1010 action PostsAction = do
11- posts <- query @ Post |> fetch
11+ posts <- query @ Post
12+ |> orderByDesc # createdAt
13+ |> fetch
1214 render IndexView { .. }
1315
1416 action NewPostAction = do
@@ -53,3 +55,4 @@ instance Controller PostsController where
5355
5456buildPost post = post
5557 |> fill @ '[" title" , " body" ]
58+ |> validateField # title nonEmpty
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ instance View IndexView where
1515 <th>Post</th>
1616 <th></th>
1717 <th></th>
18- <th></th>
1918 </tr>
2019 </thead>
2120 <tbody>{forEach posts renderPost}</tbody>
@@ -31,8 +30,7 @@ instance View IndexView where
3130renderPost :: Post -> Html
3231renderPost post = [hsx |
3332 <tr>
34- <td>{post}</td>
35- <td><a href={ShowPostAction post.id}>Show</a></td>
33+ <td><a href={ShowPostAction post.id}>{post.title}</a></td>
3634 <td><a href={EditPostAction post.id} class="text-muted">Edit</a></td>
3735 <td><a href={DeletePostAction post.id} class="js-delete text-muted">Delete</a></td>
3836 </tr>
Original file line number Diff line number Diff line change 11module Web.View.Posts.Show where
22import Web.View.Prelude
3+ import qualified Text.MMark as MMark
4+
35
46data ShowView = ShowView { post :: Post }
57
68instance View ShowView where
79 html ShowView { .. } = [hsx |
810 {breadcrumb}
9- <h1>Show Post</h1>
10- <p>{post}</p>
11+ <h1>{post.title}</h1>
12+ <p>{post.createdAt |> timeAgo}</p>
13+ <div>{post.body |> renderMarkdown}</div>
14+
1115
1216 |]
1317 where
1418 breadcrumb = renderBreadcrumb
1519 [ breadcrumbLink " Posts" PostsAction
1620 , breadcrumbText " Show Post"
17- ]
21+ ]
22+
Original file line number Diff line number Diff line change 2828 base
2929 wai
3030 text
31+ mmark
3132
3233 # Uncomment on local development for testing
3334 # hspec
You can’t perform that action at this time.
0 commit comments