mirror of
https://github.com/Damillora/Shioriko.git
synced 2025-02-23 09:23:38 +00:00
feat: make perPage param actually matter
This commit is contained in:
parent
3ff0afda1c
commit
5e713d05c7
@ -47,10 +47,10 @@ func postGet(c *gin.Context) {
|
|||||||
var postPages int
|
var postPages int
|
||||||
|
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
posts = services.GetPostTags(page, tags)
|
posts = services.GetPostTags(page, perPage, tags)
|
||||||
postPages = services.CountPostPagesTag(tags)
|
postPages = services.CountPostPagesTag(tags)
|
||||||
} else {
|
} else {
|
||||||
posts = services.GetPostAll(page)
|
posts = services.GetPostAll(page, perPage)
|
||||||
postPages = services.CountPostPages()
|
postPages = services.CountPostPages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,15 +9,13 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const perPage = 20
|
func GetPostAll(page int, perPage int) []database.Post {
|
||||||
|
|
||||||
func GetPostAll(page int) []database.Post {
|
|
||||||
var posts []database.Post
|
var posts []database.Post
|
||||||
database.DB.Joins("Blob").Preload("Tags").Preload("Tags.TagType").Order("created_at desc").Offset((page - 1) * perPage).Limit(20).Find(&posts)
|
database.DB.Joins("Blob").Preload("Tags").Preload("Tags.TagType").Order("created_at desc").Offset((page - 1) * perPage).Limit(perPage).Find(&posts)
|
||||||
return posts
|
return posts
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPostTags(page int, tagSyntax []string) []database.Post {
|
func GetPostTags(page int, perPage int, tagSyntax []string) []database.Post {
|
||||||
positiveTagSyntax := []string{}
|
positiveTagSyntax := []string{}
|
||||||
negativeTagSyntax := []string{}
|
negativeTagSyntax := []string{}
|
||||||
|
|
||||||
@ -87,7 +85,7 @@ func GetPostTags(page int, tagSyntax []string) []database.Post {
|
|||||||
}
|
}
|
||||||
query.Order("created_at desc").
|
query.Order("created_at desc").
|
||||||
Offset((page - 1) * perPage).
|
Offset((page - 1) * perPage).
|
||||||
Limit(20).
|
Limit(perPage).
|
||||||
Find(&posts)
|
Find(&posts)
|
||||||
return posts
|
return posts
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user