feat: product store

This commit is contained in:
zzw
2026-08-07 15:41:18 +08:00
parent 39fb09e7df
commit 089bdc9761
15 changed files with 1313 additions and 762 deletions
+54
View File
@@ -0,0 +1,54 @@
package logic
import (
"context"
"strconv"
"product/internal/dao"
"product/internal/model"
"product/internal/svc"
"product/product"
"product/validator"
"pkg.local/log"
"pkg.local/modelbase"
"pkg.local/utils"
validateService "pkg.local/validate"
"github.com/zeromicro/go-zero/core/logx"
)
type InfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
return &InfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *InfoLogic) Info(in *product.InfoReq) (*product.Response, error) {
var req validator.ProductInfoValidator
if msg := validateService.ValidateFromProto(in, &req); msg != utils.StringEmpty {
return msgResponse(utils.Ok.Code, msg), nil
}
var info dao.ProductInfo
err := model.ProductModel{}.Init().GetOne(modelbase.Params{
Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)},
}, &info)
if err != nil {
log.Errorf("product info: %v", err)
return failResponse(utils.Fail), nil
}
if info.Id < 1 {
return failResponse(utils.ErrorNotFund), nil
}
return okResponse(utils.StructToJson(toProductItem(info))), nil
}