From fb5f8ca2a5c5c35e6797dfdbc3c3677e59295bff Mon Sep 17 00:00:00 2001 From: Eg <1711788888@qq.com> Date: Thu, 2 Jun 2022 16:22:01 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user.go | 32 ++++++++++++++++++++++++++++++++ repository/user.go | 7 +++++++ route/user.go | 10 ++++++++++ 3 files changed, 49 insertions(+) create mode 100644 api/user.go create mode 100644 repository/user.go create mode 100644 route/user.go diff --git a/api/user.go b/api/user.go new file mode 100644 index 0000000..cc73b75 --- /dev/null +++ b/api/user.go @@ -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) +} diff --git a/repository/user.go b/repository/user.go new file mode 100644 index 0000000..2fa8572 --- /dev/null +++ b/repository/user.go @@ -0,0 +1,7 @@ +package repository + +type userService struct{} + +func UserService() *userService { + return &userService{} +} diff --git a/route/user.go b/route/user.go new file mode 100644 index 0000000..2907446 --- /dev/null +++ b/route/user.go @@ -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) // 获取用户详情 +}