@@ -1,6 +1,7 @@
package v1
import (
+ "github.com/runningwater/gohub/app/models/user"
"github.com/runningwater/gohub/pkg/auth"
"github.com/runningwater/gohub/pkg/response"
@@ -16,3 +17,9 @@ func (ctrl *UsersController) CurrentUser(c *gin.Context) {
users := auth.CurrentUser(c)
response.Data(c, users)
}
+
+// Index 所有用户
+func (ctrl *UsersController) Index(c *gin.Context) {
+ data := user.All()
+ response.Data(c, data)
+}
@@ -37,3 +37,9 @@ func Get(idStr string) (userModel User) {
database.DB.Where("id =?", idStr).First(&userModel)
return
+// All 查询所有用户
+func All() (users []User) {
+ database.DB.Find(&users)
+ return
@@ -54,6 +54,7 @@ func RegisterAPIRoutes(router *gin.Engine) {
uc := new(controllers.UsersController)
// 当前登录用户信息
authGroup.GET("/user", middlewares.AuthJWT(), uc.CurrentUser)
+ authGroup.GET("/users", middlewares.AuthJWT(), uc.Index)