fix
This commit is contained in:
parent
48657f02a6
commit
51bd2ee53c
67
server/canteen/internal/handler/getcanteendetailhandler.go
Normal file
67
server/canteen/internal/handler/getcanteendetailhandler.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
server/canteen/internal/handler/routes.go
Normal file
27
server/canteen/internal/handler/routes.go
Normal file
@ -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),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
canteenTypeModel := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn)
|
||||||
canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id)
|
canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id)
|
||||||
|
@ -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 {
|
if len(req.ProductList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "product list can`t be empty")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "product list can`t be empty")
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,9 @@ type SaveCanteenProduct struct {
|
|||||||
SId string `json:"s_id"`
|
SId string `json:"s_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
server/data-transfer/internal/handler/routes.go
Normal file
37
server/data-transfer/internal/handler/routes.go
Normal file
@ -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),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
67
server/data-transfer/internal/handler/uploadlogohandler.go
Normal file
67
server/data-transfer/internal/handler/uploadlogohandler.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
67
server/data-transfer/internal/handler/uploadqrcodehandler.go
Normal file
67
server/data-transfer/internal/handler/uploadqrcodehandler.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
qrCodeModel := gmodel.NewFsQrcodeSetModel(l.svcCtx.MysqlConn)
|
||||||
qrCodeList, err := qrCodeModel.GetAll(l.ctx)
|
qrCodeList, err := qrCodeModel.GetAll(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,7 +26,7 @@ func NewGetStandardLogoListLogic(ctx context.Context, svcCtx *svc2.ServiceContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取标准logo列表
|
// 获取标准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)
|
standardLogoModel := gmodel.NewFsStandardLogoModel(l.svcCtx.MysqlConn)
|
||||||
logoList, err := standardLogoModel.GetAll(l.ctx)
|
logoList, err := standardLogoModel.GetAll(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
@ -27,7 +27,7 @@ func NewUploadQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Uplo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成base64二维码
|
// 生成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 == "" {
|
if req.Url == "" {
|
||||||
resp.SetStatus(basic.CodeApiErr, "param url is empty")
|
resp.SetStatus(basic.CodeApiErr, "param url is empty")
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ type UploadLogoRsp struct {
|
|||||||
ImgColor []string `json:"img_color"`
|
ImgColor []string `json:"img_color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
67
server/product/internal/handler/getproductlisthandler.go
Normal file
67
server/product/internal/handler/getproductlisthandler.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
server/product/internal/handler/getsizebyproducthandler.go
Normal file
55
server/product/internal/handler/getsizebyproducthandler.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
server/product/internal/handler/routes.go
Normal file
32
server/product/internal/handler/routes.go
Normal file
@ -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),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
@ -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) {
|
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
resp = &types.Response{}
|
|
||||||
//如果是demo
|
//如果是demo
|
||||||
if req.IsDemo == 1 {
|
if req.IsDemo == 1 {
|
||||||
var demo types.GetProductListRsp
|
var demo types.GetProductListRsp
|
||||||
|
@ -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)
|
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||||
tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE)
|
tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE)
|
||||||
|
@ -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) {
|
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
resp = &types.Response{}
|
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
||||||
|
@ -96,6 +96,9 @@ type PriceObj struct {
|
|||||||
Price float64 `json:"price"`
|
Price float64 `json:"price"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user