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) {
|
||||
limit, limitStatus := c.GetQuery("limit")
|
||||
offset, offsetStatus := c.GetQuery("offset")
|
||||
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: &limit,
|
||||
LimitStatus: &limitStatus,
|
||||
Offset: &offset,
|
||||
OffsetStatus: &offsetStatus,
|
||||
Context: c,
|
||||
Limit: query.Limit,
|
||||
Offset: query.Offset,
|
||||
}
|
||||
|
||||
result := self.svc.ListUsers(userListPayload)
|
||||
|
||||
Reference in New Issue
Block a user