49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package user
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"juwan-backend/app/users/api/internal/contextx"
|
|
"juwan-backend/app/users/rpc/usercenter"
|
|
|
|
"juwan-backend/app/users/api/internal/svc"
|
|
"juwan-backend/app/users/api/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateUserInfoLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 修改用户信息
|
|
func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInfoLogic {
|
|
return &UpdateUserInfoLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateUserInfoLogic) UpdateUserInfo(req *types.UpdateUserInfoReq) (resp *types.UpdateUserInfoResp, err error) {
|
|
userId, err := contextx.UserIDFrom(l.ctx)
|
|
if err != nil {
|
|
return nil, errors.New("user not found")
|
|
}
|
|
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
|
Id: userId,
|
|
Nickname: req.Nickname,
|
|
Avatar: req.Avatar,
|
|
Bio: req.Bio,
|
|
})
|
|
if err != nil {
|
|
return nil, errors.New("update user info failed")
|
|
}
|
|
return
|
|
}
|