Skip to content

Commit a893edb

Browse files
committed
fix: update user profile with cache; add name and avatar in login resp
1 parent 0b72250 commit a893edb

File tree

4 files changed

+79
-54
lines changed

4 files changed

+79
-54
lines changed

biz/application/dto/core_api/common.pb.go

Lines changed: 63 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

biz/application/service/user.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,16 @@ func (u *UserService) Login(ctx context.Context, req *core_api.BasicUserLoginReq
195195
if strings.HasPrefix(req.AuthType, "phone-") {
196196
phone = req.AuthId
197197
}
198-
if _, err = u.UserMapper.FindOrCreateUser(ctx, id, phone, true); err != nil {
198+
var usr *user.User
199+
if usr, err = u.UserMapper.FindOrCreateUser(ctx, id, phone, true); err != nil {
199200
return nil, errorx.WrapByCode(err, errno.ErrLogin)
200201
}
201202
return &core_api.BasicUserLoginResp{
202-
Resp: util.Success(),
203-
Token: resp["token"].(string),
204-
New: resp["new"].(bool),
203+
Resp: util.Success(),
204+
Token: resp["token"].(string),
205+
New: resp["new"].(bool),
206+
Name: usr.Name,
207+
Avatar: usr.Avatar,
205208
}, nil
206209
}
207210
}

biz/infra/mapper/user/mapper.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ const (
2727
type MongoMapper interface {
2828
FindOrCreateUser(ctx context.Context, id string, phone string, login bool) (*User, error) // 查找或创建一个用户
2929
FindById(ctx context.Context, id string) (*User, error)
30+
3031
CheckForbidden(ctx context.Context, id string) (int, bool, time.Time, error)
3132
Warn(ctx context.Context, id string) error
3233
Forbidden(ctx context.Context, id string, expire time.Time) error
3334
UnForbidden(ctx context.Context, id string) error
3435
ListUser(ctx context.Context, page *basic.Page, status, sortedBy, reverse int32) (int64, []*User, error)
35-
UpdateField(ctx context.Context, uid primitive.ObjectID, update bson.M) error
3636

37+
UpdateField(ctx context.Context, uid primitive.ObjectID, update bson.M) error
3738
existField(ctx context.Context, field string, value interface{}) (bool, error)
3839
ExistUsername(ctx context.Context, username string) (bool, error)
3940
}
@@ -173,7 +174,8 @@ func (m *mongoMapper) ListUser(ctx context.Context, page *basic.Page, status, so
173174

174175
// UpdateField 更新字段
175176
func (m *mongoMapper) UpdateField(ctx context.Context, uid primitive.ObjectID, update bson.M) error {
176-
if _, err := m.conn.UpdateByIDNoCache(ctx, uid, bson.M{"$set": update}); err != nil {
177+
key := cacheKeyPrefix + uid.Hex()
178+
if _, err := m.conn.UpdateByID(ctx, key, uid, bson.M{"$set": update}); err != nil {
177179
logs.CtxErrorf(ctx, "failed to update user %s: %s", uid.Hex(), errorx.ErrorWithoutStack(err))
178180
return err
179181
}

main.go

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)