From 4a31759f455e9f66de4a72a06e22cf5609439d2f Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 15 Sep 2022 22:44:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/actions.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/route/actions.go b/route/actions.go index 25b9cc9..bdce0f6 100644 --- a/route/actions.go +++ b/route/actions.go @@ -3,6 +3,7 @@ package route import ( "fmt" "github.com/gin-gonic/gin" + "github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/models" "math" "net/http" @@ -16,6 +17,10 @@ var PostsCache sync.Map func index(c *gin.Context) { page := 1 pageSize := 10 + order := c.Query("order") + if !helper.IsContainInArr(order, []string{"asc", "desc"}) { + order = "desc" + } p := c.Query("paged") if p == "" { p = c.Param("page") @@ -29,7 +34,7 @@ func index(c *gin.Context) { status := []interface{}{"publish", "private"} posts, totalRaw, err := models.SimplePagination[models.WpPosts](models.SqlBuilder{{ "post_type", "post", - }, {"post_status", "in", ""}}, "ID", page, pageSize, models.SqlBuilder{{"post_date", "desc"}}, nil, status) + }, {"post_status", "in", ""}}, "ID", page, pageSize, models.SqlBuilder{{"post_date", order}}, nil, status) defer func() { if err != nil { c.Error(err)