mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-12-22 16:03:45 +00:00
feat: add total pages
This commit is contained in:
parent
ba86dd3c01
commit
fdb4250652
@ -32,12 +32,16 @@ func postGet(c *gin.Context) {
|
||||
pageParam := c.Query("page")
|
||||
page, _ := strconv.Atoi(pageParam)
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
tag := c.Query("tags")
|
||||
|
||||
tags := strings.Split(tag, " ")
|
||||
|
||||
var posts []database.Post
|
||||
var postPages int
|
||||
var perPage = 20
|
||||
|
||||
if tag != "" {
|
||||
posts = services.GetPostTags(page, tags)
|
||||
@ -47,6 +51,11 @@ func postGet(c *gin.Context) {
|
||||
postPages = services.CountPostPages()
|
||||
}
|
||||
|
||||
var totalPage = postPages / perPage
|
||||
if postPages%perPage > 0 {
|
||||
totalPage++
|
||||
}
|
||||
|
||||
var postResult []models.PostListItem
|
||||
for _, post := range posts {
|
||||
var tagStrings []string
|
||||
@ -63,6 +72,7 @@ func postGet(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, models.PostPaginationResponse{
|
||||
CurrentPage: page,
|
||||
TotalPage: totalPage,
|
||||
PostCount: postPages,
|
||||
Posts: postResult,
|
||||
})
|
||||
|
@ -28,6 +28,7 @@ type BlobSimilarResponse struct {
|
||||
}
|
||||
type PostPaginationResponse struct {
|
||||
CurrentPage int `json:"currentPage"`
|
||||
TotalPage int `json:"totalPage"`
|
||||
PostCount int `json:"postCount"`
|
||||
Posts []PostListItem `json:"posts"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user