modify line log api order
This commit is contained in:
parent
99c61b5af1
commit
2626234eeb
@ -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))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user