diff --git a/model/line_message_log.go b/model/line_message_log.go index f60e10b..98c0487 100644 --- a/model/line_message_log.go +++ b/model/line_message_log.go @@ -57,7 +57,10 @@ func GetLineMessageLogCount(where ...interface{}) (c int, err error) { } // GetLineMessageLogList - -func GetLineMessageLogList(g, u string, offset, limit int) (logs []*LineMessageLogWithUG, err error) { +func GetLineMessageLogList(g, u string, offset, limit int, orderArg string) (logs []*LineMessageLogWithUG, err error) { + if orderArg != "asc" && orderArg != "desc" { + orderArg = "desc" + } params := struct { Group string `db:"group"` User string `db:"user"` @@ -81,7 +84,7 @@ func GetLineMessageLogList(g, u string, offset, limit int) (logs []*LineMessageL } params.User = u } - order := `order by m.ctime desc` + order := fmt.Sprintf(`order by m.ctime %s`, orderArg) pager := fmt.Sprintf("offset %d limit %d", offset, limit) stmt, err := x.PrepareNamed(fmt.Sprintf("%s %s %s %s", query, where, order, pager)) diff --git a/router/api/line.go b/router/api/line.go index ab093aa..624dbcd 100644 --- a/router/api/line.go +++ b/router/api/line.go @@ -49,6 +49,10 @@ func GetLineMessageLog(c *context.Context) { g := c.DefaultQuery("group", "") u := c.DefaultQuery("user", "") + order := c.DefaultQuery("order", "desc") + if order != "asc" && order != "desc" { + order = "desc" + } where := make(map[string]string) if len(g) > 0 { @@ -66,8 +70,12 @@ func GetLineMessageLog(c *context.Context) { } page := utils.CalcPage(count, numP, numMax) + if numP == -1 { + numP = page.Total + } + page = utils.CalcPage(count, numP, numMax) - logs, err := model.GetLineMessageLogList(g, u, page.Offset, page.Limit) + logs, err := model.GetLineMessageLogList(g, u, page.Offset, page.Limit, order) if err != nil { c.ServerError(nil) return