mirror of
https://github.com/Damillora/Shioriko.git
synced 2025-02-23 09:23:38 +00:00
feat: add perPage param for posts get
This commit is contained in:
parent
95d9a97db7
commit
3ff0afda1c
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user