61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package user
|
|
|
|
import (
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/service/service_user"
|
|
"nixcn-cms/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// List retrieves a paginated list of users from the search engine.
|
|
//
|
|
// @Summary List Users
|
|
// @Description Fetches a list of users with support for pagination via limit and offset. Data is sourced from the search engine for high performance.
|
|
// @Tags User
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param limit query string false "Maximum number of users to return (default 0)"
|
|
// @Param offset query string true "Number of users to skip"
|
|
// @Success 200 {object} utils.RespStatus{data=[]data.UserSearchDoc} "Successful paginated list retrieval"
|
|
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input (Format Error)"
|
|
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error (Search Engine or Missing Offset)"
|
|
// @Security ApiKeyAuth
|
|
// @Router /user/list [get]
|
|
func (self *UserHandler) List(c *gin.Context) {
|
|
type ListQuery struct {
|
|
Limit *string `form:"limit"`
|
|
Offset *string `form:"offset"`
|
|
}
|
|
|
|
var query ListQuery
|
|
if err := c.ShouldBindQuery(&query); err != nil {
|
|
exception := new(exception.Builder).
|
|
SetStatus(exception.StatusClient).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceList).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorInvalidInput).
|
|
Throw(c).
|
|
String()
|
|
|
|
utils.HttpResponse(c, 400, exception)
|
|
return
|
|
}
|
|
|
|
userListPayload := &service_user.UserListPayload{
|
|
Context: c,
|
|
Limit: query.Limit,
|
|
Offset: query.Offset,
|
|
}
|
|
|
|
result := self.svc.ListUsers(userListPayload)
|
|
|
|
if result.Common.Exception.Original != exception.CommonSuccess {
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
|
return
|
|
}
|
|
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
|
}
|