fusenapi/server/home-user-auth/internal/logic/usersavebasicinfologic.go
2023-06-19 20:10:32 +08:00

63 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"
)
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 := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
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 gmodel.ErrRecordNotFound:
return resp.SetStatus(basic.CodeUserIdNotFoundErr)
default:
return resp.SetStatusWithMessage(basic.CodeDbUpdateErr, err.Error())
}
}
return resp.SetStatus(basic.CodeOK)
}