34 lines
969 B
Go
34 lines
969 B
Go
// Code scaffolded by goctl. Safe to edit.
|
|
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"
|
|
plantModel "sundynix-micro-go/app/plant/model"
|
|
)
|
|
|
|
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"))
|
|
plan := plantModel.SundynixCarePlan{
|
|
UserID: userId, PlantID: req.PlantId, Name: req.Name,
|
|
TargetAction: req.TargetAction, Period: req.Period, Icon: req.Icon,
|
|
}
|
|
if err := l.svcCtx.DB.Create(&plan).Error; err != nil {
|
|
return fmt.Errorf("创建养护计划失败")
|
|
}
|
|
return nil
|
|
}
|