Sort blog index correctly
This commit is contained in:
parent
415ce8db43
commit
6d609f1fae
|
@ -30,6 +30,7 @@ type ThreadsQuery struct {
|
|||
|
||||
// Ignored when using FetchThread or CountThreads.
|
||||
Limit, Offset int // if empty, no pagination
|
||||
OrderByCreated bool // defaults to order by last updated
|
||||
}
|
||||
|
||||
type ThreadAndStuff struct {
|
||||
|
@ -127,7 +128,11 @@ func FetchThreads(
|
|||
currentUserID,
|
||||
)
|
||||
}
|
||||
if q.OrderByCreated {
|
||||
qb.Add(`ORDER BY first_post.postdate DESC`)
|
||||
} else {
|
||||
qb.Add(`ORDER BY last_post.postdate DESC`)
|
||||
}
|
||||
if q.Limit > 0 {
|
||||
qb.Add(`LIMIT $? OFFSET $?`, q.Limit, q.Offset)
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ func BlogIndex(c *RequestContext) ResponseData {
|
|||
ThreadTypes: []models.ThreadType{models.ThreadTypeProjectBlogPost},
|
||||
Limit: postsPerPage,
|
||||
Offset: (page - 1) * postsPerPage,
|
||||
OrderByCreated: true,
|
||||
})
|
||||
if err != nil {
|
||||
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch blog posts for index"))
|
||||
|
|
Loading…
Reference in New Issue