增加产品列表接口

This commit is contained in:
laodaming
2023-06-01 15:32:28 +08:00
parent 5446c4123a
commit d26586c794
19 changed files with 451 additions and 11 deletions

View File

@@ -0,0 +1,8 @@
package config
import "github.com/zeromicro/go-zero/rest"
type Config struct {
rest.RestConf
DataSource string
}

View File

@@ -0,0 +1,28 @@
package handler
import (
"net/http"
"fusenapi/product/internal/logic"
"fusenapi/product/internal/svc"
"fusenapi/product/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductListReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
resp, err := l.GetProductList(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,22 @@
// Code generated by goctl. DO NOT EDIT.
package handler
import (
"net/http"
"fusenapi/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),
},
},
)
}

View File

@@ -0,0 +1,35 @@
package logic
import (
"context"
"fusenapi/utils/image"
"fusenapi/product/internal/svc"
"fusenapi/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetProductListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductListLogic {
return &GetProductListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取产品列表
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp *types.Response, err error) {
//获取合适尺寸
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//获取是否存在千人千面
return
}

View File

@@ -0,0 +1,19 @@
package svc
import (
"fusenapi/model"
"fusenapi/product/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
type ServiceContext struct {
Config config.Config
FsProductModel model.FsProductModel
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
FsProductModel: model.NewFsProductModel(sqlx.NewMysql(c.DataSource)),
}
}

View File

@@ -0,0 +1,15 @@
// Code generated by goctl. DO NOT EDIT.
package types
type GetProductListReq struct {
Cid uint32 `form:"cid"`
Size uint32 `form:"size"`
Page uint32 `form:"page"`
IsDemo uint32 `form:"is_demo" , options=0|1"`
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
}