forked from nixcn/nixcn-cms
Add full search for user table
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
1
service/user/full.go
Normal file
1
service/user/full.go
Normal file
@@ -0,0 +1 @@
|
||||
package user
|
||||
@@ -11,4 +11,5 @@ func Handler(r *gin.RouterGroup) {
|
||||
r.GET("/info", Info)
|
||||
r.POST("/checkin", Checkin)
|
||||
r.PATCH("/update", Update)
|
||||
r.GET("/list", List)
|
||||
}
|
||||
|
||||
50
service/user/list.go
Normal file
50
service/user/list.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"nixcn-cms/data"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func List(c *gin.Context) {
|
||||
data := new(data.User)
|
||||
|
||||
// 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 := data.FastListUsers(limitNum, offsetNum)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{
|
||||
"status": "failed list users from meilisearch",
|
||||
})
|
||||
}
|
||||
c.JSON(200, list)
|
||||
}
|
||||
Reference in New Issue
Block a user