From 3d323594db03520ff00957182cd028c9c80574c8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 17:18:43 +0800 Subject: [PATCH 1/2] fix --- .../handler/getcanteendetailhandler.go | 67 ------------------- server/canteen/internal/handler/routes.go | 27 -------- .../handler/savecanteentypeproducthandler.go | 67 ------------------- .../handler/getqrcodesetlisthandler.go | 55 --------------- .../handler/getstandardlogolisthandler.go | 56 ---------------- .../data-transfer/internal/handler/routes.go | 37 ---------- .../internal/handler/uploadlogohandler.go | 67 ------------------- .../internal/handler/uploadqrcodehandler.go | 67 ------------------- .../home-user-auth/internal/handler/routes.go | 52 -------------- .../handler/useraddresslisthandler.go | 57 ---------------- .../internal/handler/userbasicinfohandler.go | 64 ------------------ .../internal/handler/userfontshandler.go | 64 ------------------ .../internal/handler/usergettypehandler.go | 64 ------------------ .../internal/handler/userloginhandler.go | 48 ------------- .../handler/usersavebasicinfohandler.go | 64 ------------------ .../handler/userstatusconfighandler.go | 64 ------------------ .../internal/handler/getproductlisthandler.go | 67 ------------------- .../handler/getsizebyproducthandler.go | 56 ---------------- .../handler/getsuccessrecommandhandler.go | 67 ------------------- server/product/internal/handler/routes.go | 32 --------- 20 files changed, 1142 deletions(-) delete mode 100644 server/canteen/internal/handler/getcanteendetailhandler.go delete mode 100644 server/canteen/internal/handler/routes.go delete mode 100644 server/canteen/internal/handler/savecanteentypeproducthandler.go delete mode 100644 server/data-transfer/internal/handler/getqrcodesetlisthandler.go delete mode 100644 server/data-transfer/internal/handler/getstandardlogolisthandler.go delete mode 100644 server/data-transfer/internal/handler/routes.go delete mode 100644 server/data-transfer/internal/handler/uploadlogohandler.go delete mode 100644 server/data-transfer/internal/handler/uploadqrcodehandler.go delete mode 100644 server/home-user-auth/internal/handler/routes.go delete mode 100644 server/home-user-auth/internal/handler/useraddresslisthandler.go delete mode 100644 server/home-user-auth/internal/handler/userbasicinfohandler.go delete mode 100644 server/home-user-auth/internal/handler/userfontshandler.go delete mode 100644 server/home-user-auth/internal/handler/usergettypehandler.go delete mode 100644 server/home-user-auth/internal/handler/userloginhandler.go delete mode 100644 server/home-user-auth/internal/handler/usersavebasicinfohandler.go delete mode 100644 server/home-user-auth/internal/handler/userstatusconfighandler.go delete mode 100644 server/product/internal/handler/getproductlisthandler.go delete mode 100644 server/product/internal/handler/getsizebyproducthandler.go delete mode 100644 server/product/internal/handler/getsuccessrecommandhandler.go delete mode 100644 server/product/internal/handler/routes.go diff --git a/server/canteen/internal/handler/getcanteendetailhandler.go b/server/canteen/internal/handler/getcanteendetailhandler.go deleted file mode 100644 index 932f64f2..00000000 --- a/server/canteen/internal/handler/getcanteendetailhandler.go +++ /dev/null @@ -1,67 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/canteen/internal/logic" - "fusenapi/server/canteen/internal/svc" - "fusenapi/server/canteen/internal/types" -) - -func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - var req types.GetCanteenDetailReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx) - resp := l.GetCanteenDetail(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/canteen/internal/handler/routes.go b/server/canteen/internal/handler/routes.go deleted file mode 100644 index 308edfa7..00000000 --- a/server/canteen/internal/handler/routes.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. -package handler - -import ( - "net/http" - - "fusenapi/server/canteen/internal/svc" - - "github.com/zeromicro/go-zero/rest" -) - -func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { - server.AddRoutes( - []rest.Route{ - { - Method: http.MethodPost, - Path: "/canteen-type/detail", - Handler: GetCanteenDetailHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/canteen-type/save", - Handler: SaveCanteenTypeProductHandler(serverCtx), - }, - }, - ) -} diff --git a/server/canteen/internal/handler/savecanteentypeproducthandler.go b/server/canteen/internal/handler/savecanteentypeproducthandler.go deleted file mode 100644 index 8a81fb62..00000000 --- a/server/canteen/internal/handler/savecanteentypeproducthandler.go +++ /dev/null @@ -1,67 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/canteen/internal/logic" - "fusenapi/server/canteen/internal/svc" - "fusenapi/server/canteen/internal/types" -) - -func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - var req types.SaveCanteenTypeProductReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx) - resp := l.SaveCanteenTypeProduct(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go deleted file mode 100644 index a366d2c0..00000000 --- a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go +++ /dev/null @@ -1,55 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/data-transfer/internal/logic" - "fusenapi/server/data-transfer/internal/svc" -) - -func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - l := logic.NewGetQrCodeSetListLogic(r.Context(), svcCtx) - resp := l.GetQrCodeSetList() - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/data-transfer/internal/handler/getstandardlogolisthandler.go b/server/data-transfer/internal/handler/getstandardlogolisthandler.go deleted file mode 100644 index 1eff3761..00000000 --- a/server/data-transfer/internal/handler/getstandardlogolisthandler.go +++ /dev/null @@ -1,56 +0,0 @@ -package handler - -import ( - "errors" - "fusenapi/server/data-transfer/internal/types" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/data-transfer/internal/logic" - "fusenapi/server/data-transfer/internal/svc" -) - -func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - l := logic.NewGetStandardLogoListLogic(r.Context(), svcCtx) - resp := l.GetStandardLogoList(userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/data-transfer/internal/handler/routes.go b/server/data-transfer/internal/handler/routes.go deleted file mode 100644 index 49deda1b..00000000 --- a/server/data-transfer/internal/handler/routes.go +++ /dev/null @@ -1,37 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. -package handler - -import ( - "net/http" - - "fusenapi/server/data-transfer/internal/svc" - - "github.com/zeromicro/go-zero/rest" -) - -func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { - server.AddRoutes( - []rest.Route{ - { - Method: http.MethodGet, - Path: "/standard-logo/list", - Handler: GetStandardLogoListHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/qrcode-set/list", - Handler: GetQrCodeSetListHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/upload/qrcode", - Handler: UploadQrcodeHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/upload/up-logo", - Handler: UploadLogoHandler(serverCtx), - }, - }, - ) -} diff --git a/server/data-transfer/internal/handler/uploadlogohandler.go b/server/data-transfer/internal/handler/uploadlogohandler.go deleted file mode 100644 index 26d18626..00000000 --- a/server/data-transfer/internal/handler/uploadlogohandler.go +++ /dev/null @@ -1,67 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/data-transfer/internal/logic" - "fusenapi/server/data-transfer/internal/svc" - "fusenapi/server/data-transfer/internal/types" -) - -func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - var req types.UploadLogoReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUploadLogoLogic(r.Context(), svcCtx) - resp := l.UploadLogo(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/data-transfer/internal/handler/uploadqrcodehandler.go b/server/data-transfer/internal/handler/uploadqrcodehandler.go deleted file mode 100644 index b3170434..00000000 --- a/server/data-transfer/internal/handler/uploadqrcodehandler.go +++ /dev/null @@ -1,67 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/data-transfer/internal/logic" - "fusenapi/server/data-transfer/internal/svc" - "fusenapi/server/data-transfer/internal/types" -) - -func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - var req types.UploadQrcodeReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUploadQrcodeLogic(r.Context(), svcCtx) - resp := l.UploadQrcode(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go deleted file mode 100644 index 5738d5a4..00000000 --- a/server/home-user-auth/internal/handler/routes.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. -package handler - -import ( - "net/http" - - "fusenapi/server/home-user-auth/internal/svc" - - "github.com/zeromicro/go-zero/rest" -) - -func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { - server.AddRoutes( - []rest.Route{ - { - Method: http.MethodPost, - Path: "/user/login", - Handler: UserLoginHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/user/fonts", - Handler: UserFontsHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/user/get-type", - Handler: UserGetTypeHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/user/basic-info", - Handler: UserSaveBasicInfoHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/user/status-config", - Handler: UserStatusConfigHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/user/basic-info", - Handler: UserBasicInfoHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/user/address-list", - Handler: UserAddressListHandler(serverCtx), - }, - }, - ) -} diff --git a/server/home-user-auth/internal/handler/useraddresslisthandler.go b/server/home-user-auth/internal/handler/useraddresslisthandler.go deleted file mode 100644 index b1f59a6f..00000000 --- a/server/home-user-auth/internal/handler/useraddresslisthandler.go +++ /dev/null @@ -1,57 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" - "fusenapi/utils/auth" -) - -func UserAddressListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - claims, err := svcCtx.ParseJwtToken(r) - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - - l := logic.NewUserAddressListLogic(r.Context(), svcCtx) - resp := l.UserAddressList(&req, userinfo) - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/userbasicinfohandler.go b/server/home-user-auth/internal/handler/userbasicinfohandler.go deleted file mode 100644 index dfbe5d59..00000000 --- a/server/home-user-auth/internal/handler/userbasicinfohandler.go +++ /dev/null @@ -1,64 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - var req types.Request - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUserBasicInfoLogic(r.Context(), svcCtx) - resp := l.UserBasicInfo(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/userfontshandler.go b/server/home-user-auth/internal/handler/userfontshandler.go deleted file mode 100644 index 512882a8..00000000 --- a/server/home-user-auth/internal/handler/userfontshandler.go +++ /dev/null @@ -1,64 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - var req types.Request - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUserFontsLogic(r.Context(), svcCtx) - resp := l.UserFonts(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/usergettypehandler.go b/server/home-user-auth/internal/handler/usergettypehandler.go deleted file mode 100644 index 45651404..00000000 --- a/server/home-user-auth/internal/handler/usergettypehandler.go +++ /dev/null @@ -1,64 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserGetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - var req types.Request - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUserGetTypeLogic(r.Context(), svcCtx) - resp := l.UserGetType(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/userloginhandler.go b/server/home-user-auth/internal/handler/userloginhandler.go deleted file mode 100644 index 3b926823..00000000 --- a/server/home-user-auth/internal/handler/userloginhandler.go +++ /dev/null @@ -1,48 +0,0 @@ -package handler - -import ( - "errors" - "fmt" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" - "fusenapi/utils/basic" -) - -// UserLoginHandler 特殊的登录获取jwt token处理 -func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.RequestUserLogin - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUserLoginLogic(r.Context(), svcCtx) - resp, token := l.UserLogin(&req) - if resp.Code == basic.CodeOK.Code { - w.Header().Add("Authorization", fmt.Sprintf("Bearer %s", token)) - } - - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go b/server/home-user-auth/internal/handler/usersavebasicinfohandler.go deleted file mode 100644 index 2969db28..00000000 --- a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go +++ /dev/null @@ -1,64 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - var req types.RequestBasicInfoForm - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx) - resp := l.UserSaveBasicInfo(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/userstatusconfighandler.go b/server/home-user-auth/internal/handler/userstatusconfighandler.go deleted file mode 100644 index 3af61458..00000000 --- a/server/home-user-auth/internal/handler/userstatusconfighandler.go +++ /dev/null @@ -1,64 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserStatusConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - } - - var req types.Request - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUserStatusConfigLogic(r.Context(), svcCtx) - resp := l.UserStatusConfig(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/product/internal/handler/getproductlisthandler.go b/server/product/internal/handler/getproductlisthandler.go deleted file mode 100644 index 08a24ead..00000000 --- a/server/product/internal/handler/getproductlisthandler.go +++ /dev/null @@ -1,67 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/product/internal/logic" - "fusenapi/server/product/internal/svc" - "fusenapi/server/product/internal/types" -) - -func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - var req types.GetProductListReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewGetProductListLogic(r.Context(), svcCtx) - resp := l.GetProductList(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/product/internal/handler/getsizebyproducthandler.go b/server/product/internal/handler/getsizebyproducthandler.go deleted file mode 100644 index 4504376c..00000000 --- a/server/product/internal/handler/getsizebyproducthandler.go +++ /dev/null @@ -1,56 +0,0 @@ -package handler - -import ( - "errors" - "fusenapi/server/product/internal/types" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/product/internal/logic" - "fusenapi/server/product/internal/svc" -) - -func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx) - resp := l.GetSizeByProduct(userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/product/internal/handler/getsuccessrecommandhandler.go b/server/product/internal/handler/getsuccessrecommandhandler.go deleted file mode 100644 index 4e78cbae..00000000 --- a/server/product/internal/handler/getsuccessrecommandhandler.go +++ /dev/null @@ -1,67 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/auth" - - "fusenapi/server/product/internal/logic" - "fusenapi/server/product/internal/svc" - "fusenapi/server/product/internal/types" -) - -func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 解析jwtToken - claims, err := svcCtx.ParseJwtToken(r) - // 如果解析出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - // 从Token里获取对应的信息 - userinfo, err := auth.GetUserInfoFormMapClaims(claims) - // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 - if err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 401, - Message: "unauthorized", - }) - logx.Info("unauthorized:", err.Error()) - return - } - - var req types.GetSuccessRecommandReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx) - resp := l.GetSuccessRecommand(&req, userinfo) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - return - } -} diff --git a/server/product/internal/handler/routes.go b/server/product/internal/handler/routes.go deleted file mode 100644 index 0599e7f7..00000000 --- a/server/product/internal/handler/routes.go +++ /dev/null @@ -1,32 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. -package handler - -import ( - "net/http" - - "fusenapi/server/product/internal/svc" - - "github.com/zeromicro/go-zero/rest" -) - -func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { - server.AddRoutes( - []rest.Route{ - { - Method: http.MethodGet, - Path: "/product/list", - Handler: GetProductListHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/product/success-recommand", - Handler: GetSuccessRecommandHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/product/get-size-by-product", - Handler: GetSizeByProductHandler(serverCtx), - }, - }, - ) -} From 51bd2ee53c36b1049ef73dc237b25b5e32c8eba3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 17:35:37 +0800 Subject: [PATCH 2/2] fix --- .../handler/getcanteendetailhandler.go | 67 +++++++++++++++++++ server/canteen/internal/handler/routes.go | 27 ++++++++ .../handler/savecanteentypeproducthandler.go | 67 +++++++++++++++++++ .../internal/logic/getcanteendetaillogic.go | 2 +- .../logic/savecanteentypeproductlogic.go | 2 +- server/canteen/internal/types/types.go | 3 + .../handler/getqrcodesetlisthandler.go | 55 +++++++++++++++ .../handler/getstandardlogolisthandler.go | 55 +++++++++++++++ .../data-transfer/internal/handler/routes.go | 37 ++++++++++ .../internal/handler/uploadlogohandler.go | 67 +++++++++++++++++++ .../internal/handler/uploadqrcodehandler.go | 67 +++++++++++++++++++ .../internal/logic/getqrcodesetlistlogic.go | 2 +- .../logic/getstandardlogolistlogic.go | 2 +- .../internal/logic/uploadlogologic.go | 2 +- .../internal/logic/uploadqrcodelogic.go | 2 +- server/data-transfer/internal/types/types.go | 3 + .../internal/handler/getproductlisthandler.go | 67 +++++++++++++++++++ .../handler/getsizebyproducthandler.go | 55 +++++++++++++++ .../handler/getsuccessrecommandhandler.go | 67 +++++++++++++++++++ server/product/internal/handler/routes.go | 32 +++++++++ .../internal/logic/getproductlistlogic.go | 3 +- .../internal/logic/getsizebyproductlogic.go | 2 +- .../logic/getsuccessrecommandlogic.go | 3 +- server/product/internal/types/types.go | 3 + 24 files changed, 681 insertions(+), 11 deletions(-) create mode 100644 server/canteen/internal/handler/getcanteendetailhandler.go create mode 100644 server/canteen/internal/handler/routes.go create mode 100644 server/canteen/internal/handler/savecanteentypeproducthandler.go create mode 100644 server/data-transfer/internal/handler/getqrcodesetlisthandler.go create mode 100644 server/data-transfer/internal/handler/getstandardlogolisthandler.go create mode 100644 server/data-transfer/internal/handler/routes.go create mode 100644 server/data-transfer/internal/handler/uploadlogohandler.go create mode 100644 server/data-transfer/internal/handler/uploadqrcodehandler.go create mode 100644 server/product/internal/handler/getproductlisthandler.go create mode 100644 server/product/internal/handler/getsizebyproducthandler.go create mode 100644 server/product/internal/handler/getsuccessrecommandhandler.go create mode 100644 server/product/internal/handler/routes.go diff --git a/server/canteen/internal/handler/getcanteendetailhandler.go b/server/canteen/internal/handler/getcanteendetailhandler.go new file mode 100644 index 00000000..f5c8d44f --- /dev/null +++ b/server/canteen/internal/handler/getcanteendetailhandler.go @@ -0,0 +1,67 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/canteen/internal/logic" + "fusenapi/server/canteen/internal/svc" + "fusenapi/server/canteen/internal/types" +) + +func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + var req types.GetCanteenDetailReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx) + resp := l.GetCanteenDetail(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/canteen/internal/handler/routes.go b/server/canteen/internal/handler/routes.go new file mode 100644 index 00000000..308edfa7 --- /dev/null +++ b/server/canteen/internal/handler/routes.go @@ -0,0 +1,27 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + "fusenapi/server/canteen/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodPost, + Path: "/canteen-type/detail", + Handler: GetCanteenDetailHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/canteen-type/save", + Handler: SaveCanteenTypeProductHandler(serverCtx), + }, + }, + ) +} diff --git a/server/canteen/internal/handler/savecanteentypeproducthandler.go b/server/canteen/internal/handler/savecanteentypeproducthandler.go new file mode 100644 index 00000000..7e5ee156 --- /dev/null +++ b/server/canteen/internal/handler/savecanteentypeproducthandler.go @@ -0,0 +1,67 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/canteen/internal/logic" + "fusenapi/server/canteen/internal/svc" + "fusenapi/server/canteen/internal/types" +) + +func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + var req types.SaveCanteenTypeProductReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx) + resp := l.SaveCanteenTypeProduct(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/canteen/internal/logic/getcanteendetaillogic.go b/server/canteen/internal/logic/getcanteendetaillogic.go index 9a751854..d24ffbef 100644 --- a/server/canteen/internal/logic/getcanteendetaillogic.go +++ b/server/canteen/internal/logic/getcanteendetaillogic.go @@ -27,7 +27,7 @@ func NewGetCanteenDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } // 获取餐厅详情 -func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq, loginInfo *auth.UserInfo) (resp *types.Response) { +func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq, loginInfo *auth.UserInfo) (resp *basic.Response) { //获取餐厅类型数据 canteenTypeModel := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn) canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id) diff --git a/server/canteen/internal/logic/savecanteentypeproductlogic.go b/server/canteen/internal/logic/savecanteentypeproductlogic.go index 6b4d9cf4..b7382b96 100644 --- a/server/canteen/internal/logic/savecanteentypeproductlogic.go +++ b/server/canteen/internal/logic/savecanteentypeproductlogic.go @@ -30,7 +30,7 @@ func NewSaveCanteenTypeProductLogic(ctx context.Context, svcCtx *svc.ServiceCont } // 保存餐厅类型的关联产品 -func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq, loginInfo *auth.UserInfo) (resp *types.Response) { +func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq, loginInfo *auth.UserInfo) (resp *basic.Response) { if len(req.ProductList) == 0 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "product list can`t be empty") } diff --git a/server/canteen/internal/types/types.go b/server/canteen/internal/types/types.go index e2774873..34a65a59 100644 --- a/server/canteen/internal/types/types.go +++ b/server/canteen/internal/types/types.go @@ -35,6 +35,9 @@ type SaveCanteenProduct struct { SId string `json:"s_id"` } +type Request struct { +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go new file mode 100644 index 00000000..190b2864 --- /dev/null +++ b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go @@ -0,0 +1,55 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/data-transfer/internal/logic" + "fusenapi/server/data-transfer/internal/svc" +) + +func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + l := logic.NewGetQrCodeSetListLogic(r.Context(), svcCtx) + resp := l.GetQrCodeSetList(userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/data-transfer/internal/handler/getstandardlogolisthandler.go b/server/data-transfer/internal/handler/getstandardlogolisthandler.go new file mode 100644 index 00000000..4c9d27f9 --- /dev/null +++ b/server/data-transfer/internal/handler/getstandardlogolisthandler.go @@ -0,0 +1,55 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/data-transfer/internal/logic" + "fusenapi/server/data-transfer/internal/svc" +) + +func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + l := logic.NewGetStandardLogoListLogic(r.Context(), svcCtx) + resp := l.GetStandardLogoList(userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/data-transfer/internal/handler/routes.go b/server/data-transfer/internal/handler/routes.go new file mode 100644 index 00000000..49deda1b --- /dev/null +++ b/server/data-transfer/internal/handler/routes.go @@ -0,0 +1,37 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + "fusenapi/server/data-transfer/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/standard-logo/list", + Handler: GetStandardLogoListHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/qrcode-set/list", + Handler: GetQrCodeSetListHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/upload/qrcode", + Handler: UploadQrcodeHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/upload/up-logo", + Handler: UploadLogoHandler(serverCtx), + }, + }, + ) +} diff --git a/server/data-transfer/internal/handler/uploadlogohandler.go b/server/data-transfer/internal/handler/uploadlogohandler.go new file mode 100644 index 00000000..8481ae57 --- /dev/null +++ b/server/data-transfer/internal/handler/uploadlogohandler.go @@ -0,0 +1,67 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/data-transfer/internal/logic" + "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" +) + +func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + var req types.UploadLogoReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewUploadLogoLogic(r.Context(), svcCtx) + resp := l.UploadLogo(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/data-transfer/internal/handler/uploadqrcodehandler.go b/server/data-transfer/internal/handler/uploadqrcodehandler.go new file mode 100644 index 00000000..2b6afa80 --- /dev/null +++ b/server/data-transfer/internal/handler/uploadqrcodehandler.go @@ -0,0 +1,67 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/data-transfer/internal/logic" + "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" +) + +func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + var req types.UploadQrcodeReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewUploadQrcodeLogic(r.Context(), svcCtx) + resp := l.UploadQrcode(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/data-transfer/internal/logic/getqrcodesetlistlogic.go b/server/data-transfer/internal/logic/getqrcodesetlistlogic.go index 5359912a..b17db08f 100644 --- a/server/data-transfer/internal/logic/getqrcodesetlistlogic.go +++ b/server/data-transfer/internal/logic/getqrcodesetlistlogic.go @@ -27,7 +27,7 @@ func NewGetQrCodeSetListLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } // 获取二维码配置列表 -func (l *GetQrCodeSetListLogic) GetQrCodeSetList(loginInfo *auth.UserInfo) (resp *types.Response) { +func (l *GetQrCodeSetListLogic) GetQrCodeSetList(loginInfo *auth.UserInfo) (resp *basic.Response) { qrCodeModel := gmodel.NewFsQrcodeSetModel(l.svcCtx.MysqlConn) qrCodeList, err := qrCodeModel.GetAll(l.ctx) if err != nil { diff --git a/server/data-transfer/internal/logic/getstandardlogolistlogic.go b/server/data-transfer/internal/logic/getstandardlogolistlogic.go index a007a83b..61785c8f 100644 --- a/server/data-transfer/internal/logic/getstandardlogolistlogic.go +++ b/server/data-transfer/internal/logic/getstandardlogolistlogic.go @@ -26,7 +26,7 @@ func NewGetStandardLogoListLogic(ctx context.Context, svcCtx *svc2.ServiceContex } // 获取标准logo列表 -func (l *GetStandardLogoListLogic) GetStandardLogoList(loginInfo *auth.UserInfo) (resp *types2.Response) { +func (l *GetStandardLogoListLogic) GetStandardLogoList(loginInfo *auth.UserInfo) (resp *basic.Response) { standardLogoModel := gmodel.NewFsStandardLogoModel(l.svcCtx.MysqlConn) logoList, err := standardLogoModel.GetAll(l.ctx) if err != nil { diff --git a/server/data-transfer/internal/logic/uploadlogologic.go b/server/data-transfer/internal/logic/uploadlogologic.go index 2f52d9a2..7e266dd2 100644 --- a/server/data-transfer/internal/logic/uploadlogologic.go +++ b/server/data-transfer/internal/logic/uploadlogologic.go @@ -25,7 +25,7 @@ func NewUploadLogoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upload } } -func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, loginInfo *auth.UserInfo) (resp *types.Response) { +func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, loginInfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) return resp.SetStatus(basic.CodeOK) diff --git a/server/data-transfer/internal/logic/uploadqrcodelogic.go b/server/data-transfer/internal/logic/uploadqrcodelogic.go index 64cef43c..8e7b6f0a 100644 --- a/server/data-transfer/internal/logic/uploadqrcodelogic.go +++ b/server/data-transfer/internal/logic/uploadqrcodelogic.go @@ -27,7 +27,7 @@ func NewUploadQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Uplo } // 生成base64二维码 -func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, loginInfo *auth.UserInfo) (resp *types.Response) { +func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, loginInfo *auth.UserInfo) (resp *basic.Response) { if req.Url == "" { resp.SetStatus(basic.CodeApiErr, "param url is empty") } diff --git a/server/data-transfer/internal/types/types.go b/server/data-transfer/internal/types/types.go index 7dcaf75f..d50c9a7c 100644 --- a/server/data-transfer/internal/types/types.go +++ b/server/data-transfer/internal/types/types.go @@ -39,6 +39,9 @@ type UploadLogoRsp struct { ImgColor []string `json:"img_color"` } +type Request struct { +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server/product/internal/handler/getproductlisthandler.go b/server/product/internal/handler/getproductlisthandler.go new file mode 100644 index 00000000..35a1d3d6 --- /dev/null +++ b/server/product/internal/handler/getproductlisthandler.go @@ -0,0 +1,67 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" +) + +func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + var req types.GetProductListReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetProductListLogic(r.Context(), svcCtx) + resp := l.GetProductList(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/product/internal/handler/getsizebyproducthandler.go b/server/product/internal/handler/getsizebyproducthandler.go new file mode 100644 index 00000000..13bcf0bb --- /dev/null +++ b/server/product/internal/handler/getsizebyproducthandler.go @@ -0,0 +1,55 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" + "fusenapi/server/product/internal/svc" +) + +func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx) + resp := l.GetSizeByProduct(userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/product/internal/handler/getsuccessrecommandhandler.go b/server/product/internal/handler/getsuccessrecommandhandler.go new file mode 100644 index 00000000..a3196ad5 --- /dev/null +++ b/server/product/internal/handler/getsuccessrecommandhandler.go @@ -0,0 +1,67 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" +) + +func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // 解析jwtToken + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + // 从Token里获取对应的信息 + userinfo, err := auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + + var req types.GetSuccessRecommandReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 + l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx) + resp := l.GetSuccessRecommand(&req, userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + // 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。 + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/product/internal/handler/routes.go b/server/product/internal/handler/routes.go new file mode 100644 index 00000000..0599e7f7 --- /dev/null +++ b/server/product/internal/handler/routes.go @@ -0,0 +1,32 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + "fusenapi/server/product/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/product/list", + Handler: GetProductListHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/product/success-recommand", + Handler: GetSuccessRecommandHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/product/get-size-by-product", + Handler: GetSizeByProductHandler(serverCtx), + }, + }, + ) +} diff --git a/server/product/internal/logic/getproductlistlogic.go b/server/product/internal/logic/getproductlistlogic.go index 45bc8625..277f8522 100644 --- a/server/product/internal/logic/getproductlistlogic.go +++ b/server/product/internal/logic/getproductlistlogic.go @@ -33,8 +33,7 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge } // 获取产品列表 -func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo *auth.UserInfo) (resp *types.Response) { - resp = &types.Response{} +func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo *auth.UserInfo) (resp *basic.Response) { //如果是demo if req.IsDemo == 1 { var demo types.GetProductListRsp diff --git a/server/product/internal/logic/getsizebyproductlogic.go b/server/product/internal/logic/getsizebyproductlogic.go index a16449c5..e01c4a10 100644 --- a/server/product/internal/logic/getsizebyproductlogic.go +++ b/server/product/internal/logic/getsizebyproductlogic.go @@ -32,7 +32,7 @@ func NewGetSizeByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } // 获取分类下的产品以及尺寸 -func (l *GetSizeByProductLogic) GetSizeByProduct(loginInfo *auth.UserInfo) (resp *types.Response) { +func (l *GetSizeByProductLogic) GetSizeByProduct(loginInfo *auth.UserInfo) (resp *basic.Response) { //获取所有网站目录 tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn) tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE) diff --git a/server/product/internal/logic/getsuccessrecommandlogic.go b/server/product/internal/logic/getsuccessrecommandlogic.go index 24360b2f..4564156e 100644 --- a/server/product/internal/logic/getsuccessrecommandlogic.go +++ b/server/product/internal/logic/getsuccessrecommandlogic.go @@ -26,8 +26,7 @@ func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext } // 获取推荐的产品列表 -func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo *auth.UserInfo) (resp *types.Response) { - resp = &types.Response{} +func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo *auth.UserInfo) (resp *basic.Response) { //获取用户信息 userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn) userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 1b74bab6..ff2759e8 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -96,6 +96,9 @@ type PriceObj struct { Price float64 `json:"price"` } +type Request struct { +} + type Response struct { Code int `json:"code"` Message string `json:"msg"`