From f6ed43229d8d02e3d85c9d6ee97547de37035bbf Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 7 Jun 2023 11:36:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- home-user-auth/internal/handler/routes.go | 2 +- .../internal/logic/usersavebasicinfologic.go | 17 +++++++++++------ server_api/home-user-auth.api | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/home-user-auth/internal/handler/routes.go b/home-user-auth/internal/handler/routes.go index 09e53cbd..5afb9dbc 100644 --- a/home-user-auth/internal/handler/routes.go +++ b/home-user-auth/internal/handler/routes.go @@ -13,7 +13,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ { - Method: http.MethodPost, + Method: http.MethodGet, Path: "/user/login", Handler: UserLoginHandler(serverCtx), }, diff --git a/home-user-auth/internal/logic/usersavebasicinfologic.go b/home-user-auth/internal/logic/usersavebasicinfologic.go index 7f545082..4a4b4a6b 100644 --- a/home-user-auth/internal/logic/usersavebasicinfologic.go +++ b/home-user-auth/internal/logic/usersavebasicinfologic.go @@ -2,6 +2,7 @@ package logic import ( "context" + "strconv" "fusenapi/home-user-auth/internal/svc" "fusenapi/home-user-auth/internal/types" @@ -28,17 +29,21 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm) (resp *types.Response) { // 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error") resp = &types.Response{} - // logx.Info(req) - // if userinfo.UserId == 0 { - // resp.SetStatusWithMessage(basic.DefaultError, "user is not exists") - // return resp - // } - userid := l.ctx.Value("userid").(int64) + userid, err := strconv.ParseInt(l.ctx.Value("userid").(string), 10, 64) + if err != nil { + resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()) + return resp + } fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userid) if err != nil { + if err == model.ErrNotFound { + resp.SetStatusWithMessage(basic.CodeOK, "user is not exists") + return resp + } logx.Error(err) + return resp } resp.SetStatus(basic.CodeOK, fsUserModel) diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 13e944d6..2cc7c5a4 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -16,7 +16,7 @@ type request { service home-user-auth { @handler UserLoginHandler - post /user/login(RequestUserLogin) returns (responseJwt); + post /user/login(RequestUserLogin) returns (response); @handler UserFontsHandler get /user/fonts(request) returns (response);