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