|
|
@@ -1,29 +1,35 @@
|
|
|
package v1
|
|
|
|
|
|
import (
|
|
|
- "github.com/runningwater/gohub/app/models/user"
|
|
|
- "github.com/runningwater/gohub/pkg/auth"
|
|
|
- "github.com/runningwater/gohub/pkg/response"
|
|
|
+ "github.com/runningwater/gohub/app/models/user"
|
|
|
+ "github.com/runningwater/gohub/app/requests"
|
|
|
+ "github.com/runningwater/gohub/pkg/auth"
|
|
|
+ "github.com/runningwater/gohub/pkg/response"
|
|
|
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
)
|
|
|
|
|
|
type UsersController struct {
|
|
|
- BaseApiController
|
|
|
+ BaseApiController
|
|
|
}
|
|
|
|
|
|
// CurrentUser 当前登录用户信息
|
|
|
func (ctrl *UsersController) CurrentUser(c *gin.Context) {
|
|
|
- users := auth.CurrentUser(c)
|
|
|
- response.Data(c, users)
|
|
|
+ users := auth.CurrentUser(c)
|
|
|
+ response.Data(c, users)
|
|
|
}
|
|
|
|
|
|
// Index 所有用户
|
|
|
func (ctrl *UsersController) Index(c *gin.Context) {
|
|
|
- // data := user.All()
|
|
|
- data, pager := user.Paginate(c, 2)
|
|
|
- response.Data(c, gin.H{
|
|
|
- "data": data,
|
|
|
- "pager": pager,
|
|
|
- })
|
|
|
+ // data := user.All()
|
|
|
+ // 输入参数校验
|
|
|
+ request := requests.PaginationRequest{}
|
|
|
+ if ok := requests.Validate(c, &request, requests.Pagination); !ok {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ data, pager := user.Paginate(c, 2)
|
|
|
+ response.Data(c, gin.H{
|
|
|
+ "data": data,
|
|
|
+ "pager": pager,
|
|
|
+ })
|
|
|
}
|