info update profile
This commit is contained in:
parent
f9595aad3f
commit
31debda97f
@ -4,6 +4,7 @@ package gmodel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fusenapi/utils/fssql"
|
||||||
"fusenapi/utils/handlers"
|
"fusenapi/utils/handlers"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -42,3 +43,9 @@ func (p *FsUserInfoModel) CreateOrUpdate(gormDB *gorm.DB, req *FsUserInfo) (resp
|
|||||||
}
|
}
|
||||||
return req, err
|
return req, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *FsUserInfoModel) MergeMetadata(userId int64, meta any) error {
|
||||||
|
return fssql.MetadataModulePATCH(m.db, "profile", FsUserInfo{}, map[string]any{
|
||||||
|
"base": meta,
|
||||||
|
}, "user_id = ?", userId)
|
||||||
|
}
|
||||||
|
@ -145,28 +145,6 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscriptionStatus 订阅状态
|
|
||||||
type SubscriptionStatus struct {
|
|
||||||
SubEmail bool `json:"all_emails"`
|
|
||||||
ItemMap *struct {
|
|
||||||
} `json:"item_map"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserAddress struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserProfile struct {
|
|
||||||
ProfileBase UserProfileBase `json:"base"`
|
|
||||||
SubStatus SubscriptionStatus `json:"sub_status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserProfileBase 个人信息
|
|
||||||
type UserProfileBase struct {
|
|
||||||
FirstName string `json:"first_name"`
|
|
||||||
LastName string `json:"last_name"`
|
|
||||||
Resetaurant string `json:"resetaurant"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 自平台的注册流程
|
// 自平台的注册流程
|
||||||
func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterToken) (user *FsUser, err error) {
|
func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterToken) (user *FsUser, err error) {
|
||||||
|
|
||||||
|
@ -35,3 +35,25 @@ func FsFloat(v float64) *float64 {
|
|||||||
func FsBool(v bool) *bool {
|
func FsBool(v bool) *bool {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SubscriptionStatus 订阅状态
|
||||||
|
type SubscriptionStatus struct {
|
||||||
|
SubEmail bool `json:"all_emails"`
|
||||||
|
ItemMap *struct {
|
||||||
|
} `json:"item_map"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserProfile struct {
|
||||||
|
ProfileBase UserProfileBase `json:"base"`
|
||||||
|
SubStatus SubscriptionStatus `json:"sub_status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserProfileBase 个人信息
|
||||||
|
type UserProfileBase struct {
|
||||||
|
FirstName string `json:"first_name"` // 首名
|
||||||
|
LastName string `json:"last_name"` // 后名
|
||||||
|
UserName string `json:"user_name"` // 用户名
|
||||||
|
Mobile string `json:"mobile"` // 电话
|
||||||
|
Resetaurant string `json:"resetaurant"` // 不知道干什么
|
||||||
|
Company string `json:"company"` // 公司
|
||||||
|
}
|
||||||
|
@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/api/info/user",
|
Path: "/api/info/user",
|
||||||
Handler: InfoHandler(serverCtx),
|
Handler: InfoHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/info/user/profile/update",
|
||||||
|
Handler: UpdateProfileHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/info/address/default",
|
Path: "/api/info/address/default",
|
||||||
|
35
server/info/internal/handler/updateprofilehandler.go
Normal file
35
server/info/internal/handler/updateprofilehandler.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/logic"
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UpdateProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.ProfileRequest
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewUpdateProfileLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.UpdateProfile(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
"fusenapi/utils/check"
|
"fusenapi/utils/check"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
@ -175,6 +176,20 @@ func TestCaseJSON_EXTRACT(t *testing.T) {
|
|||||||
|
|
||||||
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
|
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
|
||||||
// err = conn.Exec(updatesql, 6).Error
|
// err = conn.Exec(updatesql, 6).Error
|
||||||
|
fname := "asd"
|
||||||
|
r := &types.ProfileRequest{
|
||||||
|
FirstName: &fname,
|
||||||
|
}
|
||||||
|
|
||||||
|
m := map[string]any{
|
||||||
|
"base": r,
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
log.Println(string(data))
|
||||||
|
|
||||||
var result []gmodel.FsAddress
|
var result []gmodel.FsAddress
|
||||||
conn.Model(&gmodel.FsAddress{}).Find(&result)
|
conn.Model(&gmodel.FsAddress{}).Find(&result)
|
||||||
|
52
server/info/internal/logic/updateprofilelogic.go
Normal file
52
server/info/internal/logic/updateprofilelogic.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateProfileLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProfileLogic {
|
||||||
|
return &UpdateProfileLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *UpdateProfileLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *UpdateProfileLogic) UpdateProfile(req *types.ProfileRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
if !userinfo.IsUser() {
|
||||||
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := l.svcCtx.AllModels.FsUserInfo.MergeMetadata(userinfo.UserId, req)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err) // 日志记录错误
|
||||||
|
return resp.SetStatus(basic.CodeDbSqlErr, err.Error()) // 返回数据库创建错误
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *UpdateProfileLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
@ -36,6 +36,15 @@ type AddressRequest struct {
|
|||||||
State string `json:"state"` //州
|
State string `json:"state"` //州
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProfileRequest struct {
|
||||||
|
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||||
|
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||||
|
UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
||||||
|
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||||
|
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||||
|
Company *string `json:"company,optional,omitempty"` // 公司
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ service info {
|
|||||||
@handler InfoHandler
|
@handler InfoHandler
|
||||||
post /api/info/user(UserInfoRequest) returns (response);
|
post /api/info/user(UserInfoRequest) returns (response);
|
||||||
|
|
||||||
|
@handler UpdateProfileHandler
|
||||||
|
post /api/info/user/profile/update(ProfileRequest) returns (response);
|
||||||
|
|
||||||
@handler AddressDefaultHandler
|
@handler AddressDefaultHandler
|
||||||
post /api/info/address/default(AddressIdRequest) returns (response);
|
post /api/info/address/default(AddressIdRequest) returns (response);
|
||||||
|
|
||||||
@ -60,4 +63,13 @@ type (
|
|||||||
City string `json:"city"` //城市
|
City string `json:"city"` //城市
|
||||||
State string `json:"state"` //州
|
State string `json:"state"` //州
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProfileRequest {
|
||||||
|
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||||
|
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||||
|
UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
||||||
|
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||||
|
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||||
|
Company *string `json:"company,optional,omitempty"` // 公司
|
||||||
|
}
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user