Add full search for user table

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-26 03:46:54 +08:00
parent 6681ffccdf
commit 98e32b67e1
4 changed files with 63 additions and 2 deletions

1
service/user/full.go Normal file
View File

@@ -0,0 +1 @@
package user

View File

@@ -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
View 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)
}