47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package user
|
|
|
|
import (
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/service"
|
|
"nixcn-cms/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
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.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)
|
|
}
|