|
|
package user
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
|
|
type MiniEditUserInfoLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniEditUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniEditUserInfoLogic {
|
|
|
return &MiniEditUserInfoLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *MiniEditUserInfoLogic) MiniEditUserInfo(req *types.MiniEditUserInfoRequest) (resp *types.MiniEditUserInfoResponse, err error) {
|
|
|
var (
|
|
|
conn = l.svcCtx.DefaultDBConn()
|
|
|
user *domain.User
|
|
|
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
)
|
|
|
user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
|
|
|
user.Avatar = *req.Avatar
|
|
|
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}, true); err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("更新头像失败", err)
|
|
|
}
|
|
|
resp = &types.MiniEditUserInfoResponse{}
|
|
|
return
|
|
|
} |
...
|
...
|
|