fix
This commit is contained in:
parent
e1bc5fbe51
commit
9e7b3267aa
@ -0,0 +1,78 @@
|
|||||||
|
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 GetThousandFaceDesignByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从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
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
var req types.GetThousandFaceDesignByPidReq
|
||||||
|
// 如果端点有请求结构体,则使用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.NewGetThousandFaceDesignByPidLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.GetThousandFaceDesignByPid(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -102,6 +102,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/api/product/get_render_setting_by_pid",
|
Path: "/api/product/get_render_setting_by_pid",
|
||||||
Handler: GetRenderSettingByPidHandler(serverCtx),
|
Handler: GetRenderSettingByPidHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/product/get_thousand_face_design_by_pid",
|
||||||
|
Handler: GetThousandFaceDesignByPidHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetThousandFaceDesignByPidLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetThousandFaceDesignByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetThousandFaceDesignByPidLogic {
|
||||||
|
return &GetThousandFaceDesignByPidLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetThousandFaceDesignByPidLogic) GetThousandFaceDesignByPid(req *types.GetThousandFaceDesignByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
req.Pid = strings.Trim(req.Pid, " ")
|
||||||
|
if req.Pid == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
|
||||||
|
}
|
||||||
|
//获取产品信息(只是获取id)
|
||||||
|
/* productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
|
||||||
|
}
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||||
|
}*/
|
||||||
|
//获取产品设计
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
@ -366,6 +366,18 @@ type GetRenderSettingByPidRsp struct {
|
|||||||
Colors interface{} `json:"colors"`
|
Colors interface{} `json:"colors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetThousandFaceDesignByPidReq struct {
|
||||||
|
Pid string `form:"pid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetThousandFaceDesignByPidRsp struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
OptionalId int64 `json:"optional_id"`
|
||||||
|
SizeId int64 `json:"size_id"`
|
||||||
|
LogoColor []string `json:"logo_color"`
|
||||||
|
Info interface{} `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,9 @@ service product {
|
|||||||
//获取产品渲染设置
|
//获取产品渲染设置
|
||||||
@handler GetRenderSettingByPidHandler
|
@handler GetRenderSettingByPidHandler
|
||||||
get /api/product/get_render_setting_by_pid(GetRenderSettingByPidReq) returns (response);
|
get /api/product/get_render_setting_by_pid(GetRenderSettingByPidReq) returns (response);
|
||||||
|
//获取产品千人千面设计方案
|
||||||
|
@handler GetThousandFaceDesignByPidHandler
|
||||||
|
get /api/product/get_thousand_face_design_by_pid(GetThousandFaceDesignByPidReq) returns (response);
|
||||||
//*********************产品详情分解接口结束***********************
|
//*********************产品详情分解接口结束***********************
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,3 +403,14 @@ type GetRenderSettingByPidRsp {
|
|||||||
LastDesign bool `json:"last_lesign"` //是否拥有千人千面设计方案
|
LastDesign bool `json:"last_lesign"` //是否拥有千人千面设计方案
|
||||||
Colors interface{} `json:"colors"`
|
Colors interface{} `json:"colors"`
|
||||||
}
|
}
|
||||||
|
//获取产品千人千面设计方案
|
||||||
|
type GetThousandFaceDesignByPidReq {
|
||||||
|
Pid string `form:"pid"`
|
||||||
|
}
|
||||||
|
type GetThousandFaceDesignByPidRsp {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
OptionalId int64 `json:"optional_id"`
|
||||||
|
SizeId int64 `json:"size_id"`
|
||||||
|
LogoColor []string `json:"logo_color"`
|
||||||
|
Info interface{} `json:"info"`
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user