diff --git a/pkg/app/post_routes.go b/pkg/app/post_routes.go index 215193f..8d6d4d6 100644 --- a/pkg/app/post_routes.go +++ b/pkg/app/post_routes.go @@ -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() } diff --git a/pkg/services/post.go b/pkg/services/post.go index ec9ea92..73e1a4b 100644 --- a/pkg/services/post.go +++ b/pkg/services/post.go @@ -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 }