🎨 新增获取用户详情接口

master
loser 2 years ago
parent 090acb0454
commit fb5f8ca2a5

@ -0,0 +1,32 @@
package api
import (
"github.com/gin-gonic/gin"
"online_code/client"
"online_code/core"
"online_code/models/entity"
)
type userApi struct{}
func UserApi() *userApi {
return &userApi{}
}
// GetUserInfo 获取用户详情
func (userApi) GetUserInfo(ctx *gin.Context) {
// 获取用户信息
identity := ctx.Param("identity")
if identity == "" {
core.R(ctx).FailWithMessage("参数不能为空: identity")
return
}
userData := entity.UserBasic{}
err := client.MySQL.Omit("password").Where("identity = ?", identity).Take(&userData).Error
if err != nil {
core.R(ctx).FailWithMessage("获取用户信息失败: " + err.Error())
return
}
core.R(ctx).OkWithData(userData)
}

@ -0,0 +1,7 @@
package repository
type userService struct{}
func UserService() *userService {
return &userService{}
}

@ -0,0 +1,10 @@
package route
import (
"github.com/gin-gonic/gin"
"online_code/api"
)
func user(g *gin.RouterGroup) {
g.GET("/:identity", api.UserApi().GetUserInfo) // 获取用户详情
}
Loading…
Cancel
Save