30 lines
852 B
Go
30 lines
852 B
Go
package myPlant
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"sundynix-micro-go/app/plant/api/internal/svc"
|
|
"sundynix-micro-go/app/plant/api/internal/types"
|
|
"sundynix-micro-go/app/plant/rpc/plant"
|
|
)
|
|
|
|
type AddCarePlanLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewAddCarePlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCarePlanLogic {
|
|
return &AddCarePlanLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
|
}
|
|
|
|
func (l *AddCarePlanLogic) AddCarePlan(req *types.CarePlanReq) error {
|
|
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
|
_, err := l.svcCtx.PlantRpc.AddCarePlan(l.ctx, &plant.AddCarePlanReq{
|
|
UserId: userId, PlantId: req.PlantId, Name: req.Name, Icon: req.Icon,
|
|
TargetAction: req.TargetAction, Period: int32(req.Period),
|
|
})
|
|
return err
|
|
}
|