fix
This commit is contained in:
parent
6253acf53c
commit
82f1e3984f
|
@ -11,22 +11,22 @@ import (
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRecommandProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetRecommendProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.GetRecommandProductListReq
|
var req types.GetRecommendProductListReq
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewGetRecommandProductListLogic(r.Context(), svcCtx)
|
l := logic.NewGetRecommendProductListLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
rl := reflect.ValueOf(l)
|
||||||
basic.BeforeLogic(w, r, rl)
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
resp := l.GetRecommandProductList(&req, userinfo)
|
resp := l.GetRecommendProductList(&req, userinfo)
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
basic.NormalAfterLogic(w, r, resp)
|
|
@ -60,7 +60,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/product/recommand",
|
Path: "/api/product/recommand",
|
||||||
Handler: GetRecommandProductListHandler(serverCtx),
|
Handler: GetRecommendProductListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
|
|
|
@ -20,21 +20,21 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetRecommandProductListLogic struct {
|
type GetRecommendProductListLogic struct {
|
||||||
logx.Logger
|
logx.Logger
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGetRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommandProductListLogic {
|
func NewGetRecommendProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommendProductListLogic {
|
||||||
return &GetRecommandProductListLogic{
|
return &GetRecommendProductListLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
svcCtx: svcCtx,
|
svcCtx: svcCtx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetRecommendProductListLogic) GetRecommendProductList(req *types.GetRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
if req.Num > 100 || req.Num < 0 {
|
if req.Num > 100 || req.Num < 0 {
|
||||||
req.Num = 4
|
req.Num = 4
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,6 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get recommend product list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get recommend product list")
|
||||||
}
|
}
|
||||||
//超过了截取
|
|
||||||
if len(recommendProductList) > int(req.Num) {
|
|
||||||
recommendProductList = recommendProductList[:req.Num]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//资源id集合
|
//资源id集合
|
||||||
resourceIds := make([]string, 0, 50)
|
resourceIds := make([]string, 0, 50)
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetRecommandProductListReq struct {
|
type GetRecommendProductListReq struct {
|
||||||
Num int64 `form:"num,optional"`
|
Num int64 `form:"num,optional"`
|
||||||
ProductId int64 `form:"product_id"`
|
ProductId int64 `form:"product_id"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ 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 GetRecommandProductListHandler
|
@handler GetRecommendProductListHandler
|
||||||
get /api/product/recommand(GetRecommandProductListReq) returns (response);
|
get /api/product/recommand(GetRecommendProductListReq) returns (response);
|
||||||
//获取列表页推荐产品列表
|
//获取列表页推荐产品列表
|
||||||
@handler HomePageRecommendProductListHandler
|
@handler HomePageRecommendProductListHandler
|
||||||
get /api/product/home_page_recommend(HomePageRecommendProductListReq) returns (response);
|
get /api/product/home_page_recommend(HomePageRecommendProductListReq) returns (response);
|
||||||
|
@ -49,7 +49,7 @@ service product {
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取详情页推荐产品列表
|
//获取详情页推荐产品列表
|
||||||
type GetRecommandProductListReq {
|
type GetRecommendProductListReq {
|
||||||
Num int64 `form:"num,optional"`
|
Num int64 `form:"num,optional"`
|
||||||
ProductId int64 `form:"product_id"`
|
ProductId int64 `form:"product_id"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user