42 lines
920 B
Go
42 lines
920 B
Go
package userProduct
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"tianyuan-api/apps/sentinel/client/userproduct"
|
|
|
|
"tianyuan-api/apps/gateway/internal/svc"
|
|
"tianyuan-api/apps/gateway/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AddUserProductLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewAddUserProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserProductLogic {
|
|
return &AddUserProductLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AddUserProductLogic) AddUserProduct(req *types.AddUserProductReq) error {
|
|
userId, ok := l.ctx.Value("userId").(int64)
|
|
if !ok {
|
|
return errors.New("无法获取 userId")
|
|
}
|
|
_, err := l.svcCtx.UserProductRpc.CreateUserProduct(l.ctx, &userproduct.CreateUserProductRequest{
|
|
UserId: userId,
|
|
ProductId: req.ProductId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|