🎨 新增获取用户详情接口

This commit is contained in:
loser 2022-06-02 16:22:01 +08:00
parent 090acb0454
commit fb5f8ca2a5
3 changed files with 49 additions and 0 deletions

32
api/user.go Normal file
View File

@ -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)
}

7
repository/user.go Normal file
View File

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

10
route/user.go Normal file
View File

@ -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) // 获取用户详情
}