41 lines
837 B
Go
41 lines
837 B
Go
package user
|
|
|
|
import (
|
|
"nixcn-cms/data"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func List(c *gin.Context) {
|
|
// Get limit and offset from query
|
|
limit, ok := c.GetQuery("limit")
|
|
if !ok {
|
|
limit = "0"
|
|
}
|
|
offset, ok := c.GetQuery("offset")
|
|
if !ok {
|
|
c.JSON(400, gin.H{"status": "offset not found"})
|
|
return
|
|
}
|
|
|
|
// Parse string to int64
|
|
limitNum, err := strconv.ParseInt(limit, 10, 64)
|
|
if err != nil {
|
|
c.JSON(400, gin.H{"status": "parse string to int error"})
|
|
return
|
|
}
|
|
offsetNum, err := strconv.ParseInt(offset, 10, 64)
|
|
if err != nil {
|
|
c.JSON(400, gin.H{"status": "parse string to int error"})
|
|
return
|
|
}
|
|
|
|
// Get user list from search engine
|
|
list, err := new(data.User).FastListUsers(limitNum, offsetNum)
|
|
if err != nil {
|
|
c.JSON(500, gin.H{"status": "failed list users from meilisearch"})
|
|
}
|
|
c.JSON(200, list)
|
|
}
|