feat: 迁移plant
This commit is contained in:
@@ -3,10 +3,12 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
"sundynix-micro-go/app/plant/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CreatePostLogic struct {
|
||||
@@ -23,9 +25,34 @@ func NewCreatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
}
|
||||
|
||||
// 社区
|
||||
// 发布帖子
|
||||
func (l *CreatePostLogic) CreatePost(in *plant.CreatePostReq) (*plant.CommonResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &plant.CommonResp{}, nil
|
||||
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
|
||||
post := plantModel.Post{
|
||||
UserID: in.UserId,
|
||||
Title: in.Title,
|
||||
Content: in.Content,
|
||||
Location: in.Location,
|
||||
}
|
||||
if err := tx.Create(&post).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(in.ImgIds) > 0 {
|
||||
var relations []map[string]interface{}
|
||||
for _, id := range in.ImgIds {
|
||||
relations = append(relations, map[string]interface{}{
|
||||
"post_id": post.ID,
|
||||
"oss_id": id,
|
||||
})
|
||||
}
|
||||
if err := tx.Table("sundynix_post_oss").Create(relations).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user