From 3ff0afda1cf0b9418cadcad31d19161cc33fccb6 Mon Sep 17 00:00:00 2001 From: Damillora Date: Sat, 22 Feb 2025 12:13:24 +0000 Subject: [PATCH] feat: add perPage param for posts get --- pkg/app/post_routes.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/app/post_routes.go b/pkg/app/post_routes.go index a439d8f..215193f 100644 --- a/pkg/app/post_routes.go +++ b/pkg/app/post_routes.go @@ -30,18 +30,21 @@ func InitializePostRoutes(g *gin.Engine) { func postGet(c *gin.Context) { pageParam := c.Query("page") + perPageParam := c.Query("perPage") page, _ := strconv.Atoi(pageParam) - + perPage, _ := strconv.Atoi(perPageParam) if page < 1 { page = 1 } + if perPage < 1 { + perPage = 20 + } 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) @@ -59,10 +62,7 @@ func postGet(c *gin.Context) { var postResult []models.PostListItem var tagObjs []database.Tag for _, post := range posts { - - for _, tag := range post.Tags { - tagObjs = append(tagObjs, tag) - } + tagObjs = append(tagObjs, post.Tags...) postResult = append(postResult, models.PostListItem{ ID: post.ID,