feat: make perPage param actually matter

This commit is contained in:
Damillora 2025-02-22 12:59:12 +00:00
parent 3ff0afda1c
commit 5e713d05c7
2 changed files with 6 additions and 8 deletions

View File

@ -47,10 +47,10 @@ func postGet(c *gin.Context) {
var postPages int
if tag != "" {
posts = services.GetPostTags(page, tags)
posts = services.GetPostTags(page, perPage, tags)
postPages = services.CountPostPagesTag(tags)
} else {
posts = services.GetPostAll(page)
posts = services.GetPostAll(page, perPage)
postPages = services.CountPostPages()
}

View File

@ -9,15 +9,13 @@ import (
"github.com/google/uuid"
)
const perPage = 20
func GetPostAll(page int) []database.Post {
func GetPostAll(page int, perPage int) []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
}
func GetPostTags(page int, tagSyntax []string) []database.Post {
func GetPostTags(page int, perPage int, tagSyntax []string) []database.Post {
positiveTagSyntax := []string{}
negativeTagSyntax := []string{}
@ -87,7 +85,7 @@ func GetPostTags(page int, tagSyntax []string) []database.Post {
}
query.Order("created_at desc").
Offset((page - 1) * perPage).
Limit(20).
Limit(perPage).
Find(&posts)
return posts
}