fusenapi/product/internal/logic/getproductlistlogic.go

53 lines
1.2 KiB
Go
Raw Normal View History

2023-06-01 07:32:28 +00:00
package logic
import (
"context"
2023-06-01 10:34:41 +00:00
"errors"
"fusenapi/model"
2023-06-01 07:32:28 +00:00
"fusenapi/product/internal/svc"
"fusenapi/product/internal/types"
2023-06-02 04:12:51 +00:00
"fusenapi/utils/auth"
2023-06-01 10:52:15 +00:00
"fusenapi/utils/image"
2023-06-01 07:32:28 +00:00
"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,
}
}
// 获取产品列表
2023-06-02 04:12:51 +00:00
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response, err error) {
//校验前台登录情况
if loginInfo.UserId == 0 {
return &types.Response{
Code: 401,
Message: "please sign in",
}, nil
}
2023-06-01 07:32:28 +00:00
//获取合适尺寸
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//获取是否存在千人千面
2023-06-01 10:34:41 +00:00
userModel := model.NewFsUserModel(l.svcCtx.MysqlConn)
2023-06-02 04:12:51 +00:00
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
2023-06-01 10:34:41 +00:00
if err != nil {
return nil, err
}
if userInfo.Id == 0 {
return nil, errors.New("user not exists")
}
2023-06-01 07:32:28 +00:00
return
}