This commit is contained in:
laodaming 2023-07-20 17:47:28 +08:00
parent 0e72027ff3
commit 421b63846a
5 changed files with 18 additions and 18 deletions

View File

@ -13,7 +13,7 @@ import (
"fusenapi/server/product/internal/svc"
)
func HomePageRecommandProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func HomePageRecommendProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
@ -51,7 +51,7 @@ func HomePageRecommandProductListHandler(svcCtx *svc.ServiceContext) http.Handle
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
var req types.HomePageRecommandProductListReq
var req types.HomePageRecommendProductListReq
// 如果端点有请求结构体则使用httpx.Parse方法从HTTP请求体中解析请求数据
if err := httpx.Parse(r, &req); err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
@ -62,8 +62,8 @@ func HomePageRecommandProductListHandler(svcCtx *svc.ServiceContext) http.Handle
return
}
// 创建一个业务逻辑层实例
l := logic.NewHomePageRecommandProductListLogic(r.Context(), svcCtx)
resp := l.HomePageRecommandProductList(&req, userinfo)
l := logic.NewHomePageRecommendProductListLogic(r.Context(), svcCtx)
resp := l.HomePageRecommendProductList(&req, userinfo)
// 如果响应不为nil则使用httpx.OkJsonCtx方法返回JSON响应;
if resp != nil {
httpx.OkJsonCtx(r.Context(), w, resp)

View File

@ -109,8 +109,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodGet,
Path: "/api/product/home_page_recommand",
Handler: HomePageRecommandProductListHandler(serverCtx),
Path: "/api/product/home_page_recommend",
Handler: HomePageRecommendProductListHandler(serverCtx),
},
},
)

View File

@ -20,21 +20,21 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type HomePageRecommandProductListLogic struct {
type HomePageRecommendProductListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewHomePageRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomePageRecommandProductListLogic {
return &HomePageRecommandProductListLogic{
func NewHomePageRecommendProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomePageRecommendProductListLogic {
return &HomePageRecommendProductListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *HomePageRecommandProductListLogic) HomePageRecommandProductList(req *types.HomePageRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *types.HomePageRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
//查询用户信息(不用判断存在)
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
@ -126,7 +126,7 @@ func (l *HomePageRecommandProductListLogic) HomePageRecommandProductList(req *ty
mapProductSizeCount[v.ProductId] = v.Num
}
//组装返回
listRsp := make([]types.HomePageRecommandProductListRsp, 0, len(recommendProductList))
listRsp := make([]types.HomePageRecommendProductListRsp, 0, len(recommendProductList))
for _, productInfo := range recommendProductList {
minPrice, ok := mapProductMinPrice[productInfo.Id]
_, tmpOk := mapProductTemplate[productInfo.Id]
@ -143,7 +143,7 @@ func (l *HomePageRecommandProductListLogic) HomePageRecommandProductList(req *ty
if _, ok = mapProductHaveOptionFitting[productInfo.Id]; ok {
haveOptionalFitting = true
}
item := types.HomePageRecommandProductListRsp{
item := types.HomePageRecommendProductListRsp{
ProductId: productInfo.Id,
Sn: *productInfo.Sn,
Title: *productInfo.Title,

View File

@ -378,11 +378,11 @@ type GetLastProductDesignRsp struct {
Info interface{} `json:"info"`
}
type HomePageRecommandProductListReq struct {
type HomePageRecommendProductListReq struct {
Size uint32 `form:"size"`
}
type HomePageRecommandProductListRsp struct {
type HomePageRecommendProductListRsp struct {
ProductId int64 `json:"product_id"`
Sn string `json:"sn"`
Title string `json:"title"`

View File

@ -69,8 +69,8 @@ service product {
@handler GetRecommandProductListHandler
get /api/product/recommand (GetRecommandProductListReq) returns (response);
//获取列表页推荐产品列表
@handler HomePageRecommandProductListHandler
get /api/product/home_page_recommand (HomePageRecommandProductListReq) returns (response);
@handler HomePageRecommendProductListHandler
get /api/product/home_page_recommend (HomePageRecommendProductListReq) returns (response);
//*********************产品详情分解接口结束***********************
//*********************推荐产品接口开始××××××××××××××××××××××××××
@ -422,10 +422,10 @@ type GetLastProductDesignRsp {
Info interface{} `json:"info"`
}
//获取列表页推荐产品(返回是这个维度数组)
type HomePageRecommandProductListReq {
type HomePageRecommendProductListReq {
Size uint32 `form:"size"`
}
type HomePageRecommandProductListRsp {
type HomePageRecommendProductListRsp {
ProductId int64 `json:"product_id"`
Sn string `json:"sn"`
Title string `json:"title"`