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) {
|
func postGet(c *gin.Context) {
|
||||||
pageParam := c.Query("page")
|
pageParam := c.Query("page")
|
||||||
|
perPageParam := c.Query("perPage")
|
||||||
page, _ := strconv.Atoi(pageParam)
|
page, _ := strconv.Atoi(pageParam)
|
||||||
|
perPage, _ := strconv.Atoi(perPageParam)
|
||||||
if page < 1 {
|
if page < 1 {
|
||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
|
if perPage < 1 {
|
||||||
|
perPage = 20
|
||||||
|
}
|
||||||
tag := c.Query("tags")
|
tag := c.Query("tags")
|
||||||
|
|
||||||
tags := strings.Split(tag, " ")
|
tags := strings.Split(tag, " ")
|
||||||
|
|
||||||
var posts []database.Post
|
var posts []database.Post
|
||||||
var postPages int
|
var postPages int
|
||||||
var perPage = 20
|
|
||||||
|
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
posts = services.GetPostTags(page, tags)
|
posts = services.GetPostTags(page, tags)
|
||||||
@ -59,10 +62,7 @@ func postGet(c *gin.Context) {
|
|||||||
var postResult []models.PostListItem
|
var postResult []models.PostListItem
|
||||||
var tagObjs []database.Tag
|
var tagObjs []database.Tag
|
||||||
for _, post := range posts {
|
for _, post := range posts {
|
||||||
|
tagObjs = append(tagObjs, post.Tags...)
|
||||||
for _, tag := range post.Tags {
|
|
||||||
tagObjs = append(tagObjs, tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
postResult = append(postResult, models.PostListItem{
|
postResult = append(postResult, models.PostListItem{
|
||||||
ID: post.ID,
|
ID: post.ID,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user