fix
This commit is contained in:
parent
91f6970eb0
commit
8dc98d4aca
@ -28,15 +28,10 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Handler: GetCollectProductListHandler(serverCtx),
|
Handler: GetCollectProductListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodPost,
|
||||||
Path: "/api/collection/test_ai",
|
Path: "/api/collection/test_ai",
|
||||||
Handler: TestAiHandler(serverCtx),
|
Handler: TestAiHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/collection/test_pdf",
|
|
||||||
Handler: TestPdfHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func TestAiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
rl := reflect.ValueOf(l)
|
rl := reflect.ValueOf(l)
|
||||||
basic.BeforeLogic(w, r, rl)
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
resp := l.TestAi(&req, userinfo)
|
resp := l.TestAi(&req, userinfo, w)
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/collection/internal/logic"
|
|
||||||
"fusenapi/server/collection/internal/svc"
|
|
||||||
"fusenapi/server/collection/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestPdfHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.TestPdfReq
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewTestPdfLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.TestPdf(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
@ -1,50 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fusenapi/server/collection/internal/svc"
|
|
||||||
"fusenapi/server/collection/internal/types"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"fusenapi/utils/pdf"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TestPdfLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTestPdfLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestPdfLogic {
|
|
||||||
return &TestPdfLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *TestPdfLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *TestPdfLogic) TestPdf(req *types.TestPdfReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "你干嘛,哎哟")
|
|
||||||
switch req.Type {
|
|
||||||
case "url":
|
|
||||||
case "html":
|
|
||||||
default:
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid type")
|
|
||||||
}
|
|
||||||
res, err := pdf.HtmlToPdfBase64(req.Content, req.Type)
|
|
||||||
if err != nil {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeOK, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *TestPdfLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
@ -41,12 +41,7 @@ type GetCollectProductListRspItem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TestAiReq struct {
|
type TestAiReq struct {
|
||||||
Num int `form:"num"`
|
Data map[string]interface{} `json:"data"`
|
||||||
}
|
|
||||||
|
|
||||||
type TestPdfReq struct {
|
|
||||||
Content string `json:"content"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
@ -20,10 +20,7 @@ service collection {
|
|||||||
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
||||||
//测试算法合图并发
|
//测试算法合图并发
|
||||||
@handler TestAiHandler
|
@handler TestAiHandler
|
||||||
get /api/collection/test_ai(TestAiReq) returns (response);
|
post /api/collection/test_ai(TestAiReq) returns (response);
|
||||||
//测试pdf
|
|
||||||
@handler TestPdfHandler
|
|
||||||
post /api/collection/test_pdf(TestPdfReq) returns (response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//收藏产品
|
//收藏产品
|
||||||
@ -61,10 +58,5 @@ type GetCollectProductListRspItem {
|
|||||||
}
|
}
|
||||||
//测试算法
|
//测试算法
|
||||||
type TestAiReq {
|
type TestAiReq {
|
||||||
Num int `form:"num"`
|
Data map[string]interface{} `json:"data"`
|
||||||
}
|
|
||||||
//测试pdf
|
|
||||||
type TestPdfReq {
|
|
||||||
Content string `json:"content"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user