From 73e1fd09aad7ec5f0be90f549dee6863a8683e8d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 8 Jun 2023 18:55:08 +0800 Subject: [PATCH] ok --- go.mod | 3 ++ go.sum | 8 ++++++ model/fsaddressmodel.go | 24 ++++++++-------- .../home-user-auth/internal/handler/routes.go | 10 +++---- .../internal/logic/useraddresslistlogic.go | 3 ++ .../logic/useraddresslistlogic_test.go | 28 +++++++++++++++++++ server/home-user-auth/internal/types/types.go | 4 +-- server_api/home-user-auth.api | 10 +++---- 8 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 server/home-user-auth/internal/logic/useraddresslistlogic_test.go diff --git a/go.mod b/go.mod index 002880ba..78bbe9f6 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,8 @@ require ( github.com/zeromicro/go-zero v1.5.2 ) +require github.com/474420502/requests v1.22.0 // indirect + require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.2.0 // indirect @@ -19,6 +21,7 @@ require ( github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 // indirect github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect github.com/google/uuid v1.3.0 // indirect diff --git a/go.sum b/go.sum index 5bbedf7f..b4f4d08e 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/474420502/requests v1.22.0 h1:dRQczuYg3K3GlaQgm8SZQLmpiKc+jlOKzN0LkAKXUAo= +github.com/474420502/requests v1.22.0/go.mod h1:043PKfW//QR069XTYG5WT7t+z+d+8/C5PJtfWzpsf+o= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= @@ -105,6 +107,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -215,6 +219,7 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE= github.com/zeromicro/go-zero v1.5.2 h1:vpMlZacCMtgdtYzKI3OMyhS6mZ9UQctiAh0J7gIq31I= github.com/zeromicro/go-zero v1.5.2/go.mod h1:ndCd1nMMAdEMZgPfdm1fpavHUdBW0ykB6ckCRaSG10w= @@ -282,6 +287,7 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -325,6 +331,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -409,6 +416,7 @@ golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/model/fsaddressmodel.go b/model/fsaddressmodel.go index de1075ec..45370818 100755 --- a/model/fsaddressmodel.go +++ b/model/fsaddressmodel.go @@ -25,18 +25,18 @@ type ( } DataAddressList struct { - Id int64 `db:"id"` - UserId int64 `db:"user_id"` // 用户ID - Name string `db:"name"` // 地址名称 - FirstName string `db:"first_name"` // FirstName - LastName string `db:"last_name"` // LastName - Mobile string `db:"mobile"` // 手机号码 - Street string `db:"street"` // 街道 - Suite string `db:"suite"` // 房号 - City string `db:"city"` // 城市 - State string `db:"state"` // 州名 - ZipCode string `db:"zip_code"` // 邮编 - IsDefault int64 `db:"is_default"` // 1默认地址,0非默认地址 + Id int64 `db:"id" json:"id"` + UserId int64 `db:"user_id" json:"user_id"` // 用户ID + Name string `db:"name" json:"name"` // 地址名称 + FirstName string `db:"first_name" json:"first_name"` // FirstName + LastName string `db:"last_name" json:"last_name"` // LastName + Mobile string `db:"mobile" json:"mobile"` // 手机号码 + Street string `db:"street" json:"street"` // 街道 + Suite string `db:"suite" json:"suite"` // 房号 + City string `db:"city" json:"city"` // 城市 + State string `db:"state" json:"state"` // 州名 + ZipCode string `db:"zip_code" json:"zip_code"` // 邮编 + IsDefault int64 `db:"is_default" json:"is_default"` // 1默认地址,0非默认地址 } ) diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go index 9eef872f..a1e38fcf 100644 --- a/server/home-user-auth/internal/handler/routes.go +++ b/server/home-user-auth/internal/handler/routes.go @@ -22,11 +22,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/user/fonts", Handler: UserFontsHandler(serverCtx), }, - { - Method: http.MethodGet, - Path: "/user/address-list", - Handler: UserAddressListHandler(serverCtx), - }, { Method: http.MethodGet, Path: "/user/get-type", @@ -52,6 +47,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/user/basic-info", Handler: UserBasicInfoHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/user/address-list", + Handler: UserAddressListHandler(serverCtx), + }, }, rest.WithJwt(serverCtx.Config.Auth.AccessSecret), ) diff --git a/server/home-user-auth/internal/logic/useraddresslistlogic.go b/server/home-user-auth/internal/logic/useraddresslistlogic.go index e3aeec90..fc7c8b57 100644 --- a/server/home-user-auth/internal/logic/useraddresslistlogic.go +++ b/server/home-user-auth/internal/logic/useraddresslistlogic.go @@ -30,6 +30,9 @@ func (l *UserAddressListLogic) UserAddressList(req *types.Request) (resp *types. // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) m := model.NewFsAddressModel(l.svcCtx.MysqlConn) user := auth.GetUserInfoFormCtx(l.ctx) + if user.UserId == 0 { + return resp.SetStatus(basic.CodeUnAuth) + } // model里设置了 返回值. 和 types 里的一至可以直接返回 data, err := m.FindDataAddressList(l.ctx, user.UserId) if err != nil { diff --git a/server/home-user-auth/internal/logic/useraddresslistlogic_test.go b/server/home-user-auth/internal/logic/useraddresslistlogic_test.go new file mode 100644 index 00000000..8c0058ad --- /dev/null +++ b/server/home-user-auth/internal/logic/useraddresslistlogic_test.go @@ -0,0 +1,28 @@ +package logic + +import ( + "testing" +) + +func TestCaseAddressList(t *testing.T) { + + // http.NewRequest("POST", "http://localhost:8888/user/login", body io.Reader) + + // ses := requests.NewSession() + // tp := ses.Post("http://localhost:8888/user/login") + // resp, err := tp.SetBodyAuto(map[string]interface{}{ + // "name": "devenv@sina.cn", + // "pwd": "$2y$13$6UFDMZQMEfqFYiNLpiUCi.B3fpvGEamPAjIgzUqv/u7jT05nB3pOC", + // }, requests.TypeFormData).Execute() + // if err != nil { + // panic(err) + // } + // log.Println(string(resp.Content())) + + // resp, err = ses.Get("http://localhost:8888/user/address-list").Execute() + // if err != nil { + // panic(err) + // } + // log.Println(string(resp.Content())) + +} diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index c5e97122..c964fefc 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -26,8 +26,8 @@ type RequestBasicInfoForm struct { } type RequestUserLogin struct { - Name string `form:"name"` - Password string `form:"pwd"` + Name string `json:"name"` + Password string `json:"pwd"` } type DataUserLogin struct { diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 5a07b6ee..61fae409 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -21,9 +21,6 @@ service home-user-auth { @handler UserFontsHandler get /user/fonts(request) returns (response); - @handler UserAddressListHandler - get /user/address-list(request) returns (response); - @handler UserGetTypeHandler get /user/get-type(request) returns (response); @@ -41,6 +38,9 @@ service home-user-auth { service home-user-auth { @handler UserBasicInfoHandler get /user/basic-info(request) returns (response); + + @handler UserAddressListHandler + get /user/address-list(request) returns (response); } type RequestBasicInfoForm { @@ -63,8 +63,8 @@ type RequestBasicInfoForm { // UserLoginHandler 用户登录请求结构 type RequestUserLogin { - Name string `form:"name"` - Password string `form:"pwd"` + Name string `json:"name"` + Password string `json:"pwd"` } // UserLoginHandler 用户登录请求结构