feat: 初次启动
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
@@ -7,8 +6,7 @@ import (
|
||||
"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"
|
||||
"time"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
)
|
||||
|
||||
type CreatePlantLogic struct {
|
||||
@@ -23,20 +21,10 @@ func NewCreatePlantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
|
||||
|
||||
func (l *CreatePlantLogic) CreatePlant(req *types.CreatePlantReq) error {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
plantTime, _ := time.Parse("2006-01-02", req.PlantTime)
|
||||
plant := plantModel.SundynixMyPlant{
|
||||
UserID: userId, Name: req.Name, PlantTime: plantTime, Placement: req.Placement,
|
||||
_, err := l.svcCtx.PlantRpc.CreatePlant(l.ctx, &plant.CreatePlantReq{
|
||||
UserId: userId, Name: req.Name, PlantTime: req.PlantTime, Placement: req.Placement,
|
||||
PotMaterial: req.PotMaterial, PotSize: req.PotSize, Sunlight: req.Sunlight,
|
||||
PlantingMaterial: req.PlantingMaterial, Status: 1,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&plant).Error; err != nil {
|
||||
l.Errorf("创建植物失败: %v", err)
|
||||
return fmt.Errorf("创建植物失败")
|
||||
}
|
||||
if len(req.ImgIds) > 0 {
|
||||
for _, imgID := range req.ImgIds {
|
||||
l.svcCtx.DB.Create(&plantModel.SundynixMyPlantOss{MyPlantID: plant.ID, OssID: imgID})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
PlantingMaterial: req.PlantingMaterial, ImgIds: req.ImgIds,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user