-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
前端 - 管理后台头部通过接口加载用户信息,并添加骨架占位 后端 - 增加获取当前用户基本信息接口 - 用户模型增加头像、状态字段
- Loading branch information
Showing
10 changed files
with
223 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"league/common/context" | ||
"league/common/errs" | ||
"league/service" | ||
"strconv" | ||
) | ||
|
||
// GetUserinfo 获取当前用户信息 | ||
func GetUserinfo(ctx *gin.Context) { | ||
c := context.CustomContext{Context: ctx} | ||
strId := ctx.Value("UserId").(string) | ||
userId, err := strconv.ParseUint(strId, 10, 64) // 10进制 | ||
if err != nil { | ||
c.CJSON(errs.ErrAuthNoLogin) | ||
return | ||
} | ||
userService := service.NewUserService(ctx) | ||
user := userService.GetUserInfo(uint(userId)) | ||
if user == nil { | ||
c.CJSON(errs.ErrNoRecord, "没有用户信息") | ||
return | ||
} | ||
c.CJSON(errs.Success, user) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"gorm.io/gorm" | ||
"league/dal" | ||
"league/log" | ||
"league/model" | ||
) | ||
|
||
type UserService struct { | ||
Ctx *gin.Context | ||
UserDal *dal.UserDal | ||
} | ||
|
||
// NewUserService 新建AuthService实例 | ||
func NewUserService(ctx *gin.Context) *UserService { | ||
return &UserService{ | ||
Ctx: ctx, | ||
UserDal: dal.NewUserDal(ctx), | ||
} | ||
} | ||
|
||
// GetUserInfo 根据用户ID获取用户基本信息 | ||
func (u *UserService) GetUserInfo(id uint) *model.User { | ||
user := &model.User{ | ||
Model: gorm.Model{ID: id}, | ||
} | ||
result, err := u.UserDal.GetUserinfo(user, 0, 1) | ||
if err != nil { | ||
log.Errorf(u.Ctx, "Get userinfo failed, err: %s", err.Error()) | ||
return nil | ||
} | ||
if result == nil || result.Count == 0 || len(result.List) == 0 { | ||
return nil | ||
} | ||
return result.List[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.