Skip to content

Commit

Permalink
closes #12; modify getCommentsBySlug query
Browse files Browse the repository at this point in the history
  • Loading branch information
aliml92 committed Aug 1, 2023
1 parent 65499f7 commit 20ff31a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
8 changes: 4 additions & 4 deletions api/article_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,10 @@ func newCommentsResponse(
}, len(comments)),
}
for i, comment := range comments {
res.Comments[i].ID = comment.ID
res.Comments[i].CreatedAt = comment.CreatedAt
res.Comments[i].UpdatedAt = comment.UpdatedAt
res.Comments[i].Body = comment.Body
res.Comments[i].ID = &comment.ID
res.Comments[i].CreatedAt = &comment.CreatedAt
res.Comments[i].UpdatedAt = &comment.UpdatedAt
res.Comments[i].Body = &comment.Body
res.Comments[i].Author.Username = comment.Username
res.Comments[i].Author.Bio = comment.Bio
res.Comments[i].Author.Image = comment.Image
Expand Down
13 changes: 5 additions & 8 deletions db/query/article.sql
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,11 @@ SELECT
u.id AS author_id,
u.username,
u.bio,
u.image
FROM (
SELECT id
FROM articles
WHERE slug = $1
) a
LEFT JOIN comments c ON a.id = c.article_id
LEFT JOIN users u ON c.author_id = u.id;
u.image
FROM comments c
LEFT JOIN articles a ON a.id = c.article_id
LEFT JOIN users u ON u.id = c.author_id
WHERE a.slug = $1;

-- name: GetArticlesByTag :many
WITH article_tags_cte AS (
Expand Down
29 changes: 13 additions & 16 deletions db/sqlc/article.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20ff31a

Please sign in to comment.