Optomize user list service query bind struct
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -9,15 +9,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (self *UserHandler) List(c *gin.Context) {
|
func (self *UserHandler) List(c *gin.Context) {
|
||||||
limit, limitStatus := c.GetQuery("limit")
|
type ListQuery struct {
|
||||||
offset, offsetStatus := c.GetQuery("offset")
|
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{
|
userListPayload := &service.UserListPayload{
|
||||||
Context: c,
|
Context: c,
|
||||||
Limit: &limit,
|
Limit: query.Limit,
|
||||||
LimitStatus: &limitStatus,
|
Offset: query.Offset,
|
||||||
Offset: &offset,
|
|
||||||
OffsetStatus: &offsetStatus,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result := self.svc.ListUsers(userListPayload)
|
result := self.svc.ListUsers(userListPayload)
|
||||||
|
|||||||
@@ -281,9 +281,7 @@ func (self *UserServiceImpl) UpdateUserInfo(payload *UserInfoPayload) (result *U
|
|||||||
type UserListPayload struct {
|
type UserListPayload struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Limit *string
|
Limit *string
|
||||||
LimitStatus *bool
|
|
||||||
Offset *string
|
Offset *string
|
||||||
OffsetStatus *bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserListResult struct {
|
type UserListResult struct {
|
||||||
@@ -294,12 +292,12 @@ type UserListResult struct {
|
|||||||
// ListUsers
|
// ListUsers
|
||||||
func (self *UserServiceImpl) ListUsers(payload *UserListPayload) (result *UserListResult) {
|
func (self *UserServiceImpl) ListUsers(payload *UserListPayload) (result *UserListResult) {
|
||||||
var limit string
|
var limit string
|
||||||
if !*payload.LimitStatus || *payload.Limit == "" {
|
if payload.Limit == nil || *payload.Limit == "" {
|
||||||
limit = "0"
|
limit = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
var offset string
|
var offset string
|
||||||
if !*payload.OffsetStatus || *payload.Offset == "" {
|
if payload.Offset == nil || *payload.Offset == "" {
|
||||||
exception := new(exception.Builder).
|
exception := new(exception.Builder).
|
||||||
SetStatus(exception.StatusUser).
|
SetStatus(exception.StatusUser).
|
||||||
SetService(exception.ServiceUser).
|
SetService(exception.ServiceUser).
|
||||||
|
|||||||
Reference in New Issue
Block a user