fusenapi/server/home-user-auth/internal/logic/usersavebasicinfologic.go
2023-06-21 14:26:29 +08:00

64 lines
1.6 KiB
Go

package logic
import (
"context"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type UserSaveBasicInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserSaveBasicInfoLogic {
return &UserSaveBasicInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *basic.Response) {
if !userinfo.IsUser() {
return resp.SetStatus(basic.CodeUnAuth)
}
m := l.svcCtx.AllModels.FsUser
err := m.UpdateUserBasicInfoById(l.ctx, userinfo.UserId, &gmodel.UserBasicInfoForSave{
FirstName: req.FirstName,
LastName: req.LastName,
Mobile: req.Mobile,
Company: req.Company,
IsOrderStatusEmail: req.IsOrderStatusEmail,
IsEmailAdvertisement: req.IsEmailAdvertisement,
IsOrderStatusPhone: req.IsOrderStatusPhone,
IsPhoneAdvertisement: req.IsPhoneAdvertisement,
Type: req.Type,
IsOpenRender: req.IsOpenRender,
IsLowRendering: req.IsLowRendering,
IsRemoveBg: req.IsRemoveBg,
})
if err != nil {
logx.Error(err)
switch err {
case gorm.ErrRecordNotFound:
return resp.SetStatus(basic.CodeUserIdNotFoundErr)
default:
return resp.SetStatusWithMessage(basic.CodeDbUpdateErr, err.Error())
}
}
return resp.SetStatus(basic.CodeOK)
}