From 54613f5be0f4ddd904e17fcb0f445c2a0f97763d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 26 Sep 2023 17:45:07 +0800 Subject: [PATCH 1/3] info get profile --- server/info/internal/handler/routes.go | 2 +- ...profilehandler.go => updateprofilebasehandler.go} | 8 ++++---- ...dateprofilelogic.go => updateprofilebaselogic.go} | 12 ++++++------ server/info/internal/types/types.go | 2 +- server_api/info.api | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) rename server/info/internal/handler/{updateprofilehandler.go => updateprofilebasehandler.go} (70%) rename server/info/internal/logic/{updateprofilelogic.go => updateprofilebaselogic.go} (66%) diff --git a/server/info/internal/handler/routes.go b/server/info/internal/handler/routes.go index 4852a939..a6113d5c 100644 --- a/server/info/internal/handler/routes.go +++ b/server/info/internal/handler/routes.go @@ -25,7 +25,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { { Method: http.MethodPost, Path: "/api/info/user/profile/update", - Handler: UpdateProfileHandler(serverCtx), + Handler: UpdateProfileBaseHandler(serverCtx), }, { Method: http.MethodPost, diff --git a/server/info/internal/handler/updateprofilehandler.go b/server/info/internal/handler/updateprofilebasehandler.go similarity index 70% rename from server/info/internal/handler/updateprofilehandler.go rename to server/info/internal/handler/updateprofilebasehandler.go index 6e06b51f..73670c61 100644 --- a/server/info/internal/handler/updateprofilehandler.go +++ b/server/info/internal/handler/updateprofilebasehandler.go @@ -11,22 +11,22 @@ import ( "fusenapi/server/info/internal/types" ) -func UpdateProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func UpdateProfileBaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ProfileRequest + var req types.ProfileBaseRequest userinfo, err := basic.RequestParse(w, r, svcCtx, &req) if err != nil { return } // 创建一个业务逻辑层实例 - l := logic.NewUpdateProfileLogic(r.Context(), svcCtx) + l := logic.NewUpdateProfileBaseLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.UpdateProfile(&req, userinfo) + resp := l.UpdateProfileBase(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/info/internal/logic/updateprofilelogic.go b/server/info/internal/logic/updateprofilebaselogic.go similarity index 66% rename from server/info/internal/logic/updateprofilelogic.go rename to server/info/internal/logic/updateprofilebaselogic.go index 49be7b52..12e9e3cd 100644 --- a/server/info/internal/logic/updateprofilelogic.go +++ b/server/info/internal/logic/updateprofilebaselogic.go @@ -12,14 +12,14 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type UpdateProfileLogic struct { +type UpdateProfileBaseLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewUpdateProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProfileLogic { - return &UpdateProfileLogic{ +func NewUpdateProfileBaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProfileBaseLogic { + return &UpdateProfileBaseLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -27,10 +27,10 @@ func NewUpdateProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd } // 处理进入前逻辑w,r -// func (l *UpdateProfileLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *UpdateProfileBaseLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -func (l *UpdateProfileLogic) UpdateProfile(req *types.ProfileRequest, userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileBaseRequest, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null if !userinfo.IsUser() { @@ -47,6 +47,6 @@ func (l *UpdateProfileLogic) UpdateProfile(req *types.ProfileRequest, userinfo * } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *UpdateProfileLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *UpdateProfileBaseLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } diff --git a/server/info/internal/types/types.go b/server/info/internal/types/types.go index 5a2df57e..a3fbf2f8 100644 --- a/server/info/internal/types/types.go +++ b/server/info/internal/types/types.go @@ -36,7 +36,7 @@ type AddressRequest struct { State string `json:"state"` //州 } -type ProfileRequest struct { +type ProfileBaseRequest struct { FirstName *string `json:"first_name,optional,omitempty"` // 首名 LastName *string `json:"last_name,optional,omitempty"` // 后名 UserName *string `json:"user_name,optional,omitempty"` // 用户名 diff --git a/server_api/info.api b/server_api/info.api index c2ab7439..deab2b82 100644 --- a/server_api/info.api +++ b/server_api/info.api @@ -16,8 +16,8 @@ service info { @handler UserGetProfileHandler post /api/info/user/profile(QueryProfileRequest) returns (response); - @handler UpdateProfileHandler - post /api/info/user/profile/update(ProfileRequest) returns (response); + @handler UpdateProfileBaseHandler + post /api/info/user/profile/update(ProfileBaseRequest) returns (response); @handler AddressDefaultHandler post /api/info/address/default(AddressIdRequest) returns (response); @@ -67,7 +67,7 @@ type ( State string `json:"state"` //州 } - ProfileRequest { + ProfileBaseRequest { FirstName *string `json:"first_name,optional,omitempty"` // 首名 LastName *string `json:"last_name,optional,omitempty"` // 后名 UserName *string `json:"user_name,optional,omitempty"` // 用户名 From b571b1b31cc9135c0c43ca9c1e04223222468b77 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 26 Sep 2023 17:57:54 +0800 Subject: [PATCH 2/3] info get profile --- server_api/info.api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_api/info.api b/server_api/info.api index deab2b82..1770f022 100644 --- a/server_api/info.api +++ b/server_api/info.api @@ -17,7 +17,7 @@ service info { post /api/info/user/profile(QueryProfileRequest) returns (response); @handler UpdateProfileBaseHandler - post /api/info/user/profile/update(ProfileBaseRequest) returns (response); + post /api/info/user/profile/base/update(ProfileBaseRequest) returns (response); @handler AddressDefaultHandler post /api/info/address/default(AddressIdRequest) returns (response); From 91c1c580f95da62f00897dc71bbdbb3031c11326 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 26 Sep 2023 18:03:29 +0800 Subject: [PATCH 3/3] info get profile --- server/info/internal/handler/routes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/info/internal/handler/routes.go b/server/info/internal/handler/routes.go index a6113d5c..b2194efd 100644 --- a/server/info/internal/handler/routes.go +++ b/server/info/internal/handler/routes.go @@ -24,7 +24,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodPost, - Path: "/api/info/user/profile/update", + Path: "/api/info/user/profile/base/update", Handler: UpdateProfileBaseHandler(serverCtx), }, {