fusenapi/server/home-user-auth/internal/logic/usersavebasicinfologic.go

64 lines
1.6 KiB
Go
Raw Normal View History

2023-06-05 09:56:55 +00:00
package logic
import (
"context"
2023-06-15 08:08:43 +00:00
"fusenapi/model/gmodel"
2023-06-07 03:35:04 +00:00
"fusenapi/utils/auth"
2023-06-05 09:56:55 +00:00
2023-06-08 02:51:56 +00:00
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
2023-06-05 09:56:55 +00:00
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
2023-06-21 03:29:09 +00:00
"gorm.io/gorm"
2023-06-05 09:56:55 +00:00
)
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,
}
}
2023-06-12 10:08:34 +00:00
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *basic.Response) {
2023-06-15 08:08:43 +00:00
if !userinfo.IsUser() {
return resp.SetStatus(basic.CodeUnAuth)
2023-06-07 03:36:29 +00:00
}
2023-06-15 08:08:43 +00:00
2023-06-21 06:26:29 +00:00
m := l.svcCtx.AllModels.FsUser
2023-06-15 09:51:06 +00:00
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 {
2023-06-21 03:29:09 +00:00
case gorm.ErrRecordNotFound:
2023-06-15 09:51:06 +00:00
return resp.SetStatus(basic.CodeUserIdNotFoundErr)
default:
2023-06-19 12:10:32 +00:00
return resp.SetStatusWithMessage(basic.CodeDbUpdateErr, err.Error())
2023-06-15 09:51:06 +00:00
}
2023-06-05 09:56:55 +00:00
}
2023-06-15 08:08:43 +00:00
return resp.SetStatus(basic.CodeOK)
2023-06-05 09:56:55 +00:00
}